As there is no officially supported integration that really works I've prepared a simple CI/CD pipelines to cover vercel's preview and production environments.
<name>_dev
,<name>_stage
,<name>
import { createMiddleware } from '@rescale/nemo'; | |
import { internalMiddleware } from '@/app/(platform)/(personal)/_middleware'; | |
const middlewares = { | |
'/(home|settings){/:path}?': internalMiddleware, | |
}; | |
export const middleware = createMiddleware( | |
middlewares as never, | |
); |
#!/bin/bash | |
# Project settings | |
PROJECT_DIR="<PROJECT DIR>" | |
# Function to log messages with date and time | |
log_message() { | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] $1" | |
} |
import type { NextRequest, NextResponse } from 'next/server'; | |
import { CronJob, type ErrorResponse } from '@rescale/cron'; | |
// [...] | |
interface CombinedResponse { | |
updateSubscriptions: UpdateSubscriptionResponse[]; | |
sendNewsletter: SendNewsletterResponse[]; | |
} |
/** | |
* The fallback IP address to use if the real IP address cannot be determined. | |
*/ | |
const FALLBACK_IP_ADDRESS = '0.0.0.0'; | |
/** | |
* Returns the real IP address of the client. | |
* @param request - The incoming request. | |
* @param cfProxy - Whether the client is behind a Cloudflare proxy. | |
* @returns The real IP address of the client. |
// example code source: https://github.com/vercel/next.js/blob/canary/examples/middleware/middleware.ts | |
import { NextRequest, NextResponse } from 'next/server' | |
export function middleware(request: NextRequest) { | |
if (request.nextUrl.pathname === '/about') { | |
return NextResponse.redirect(new URL('/redirected', request.url)) | |
} | |
if (request.nextUrl.pathname === '/another') { | |
return NextResponse.rewrite(new URL('/rewrite', request.url)) |