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>
// 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)) |
/** | |
* 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. |
import type { NextRequest, NextResponse } from 'next/server'; | |
import { CronJob, type ErrorResponse } from '@rescale/cron'; | |
// [...] | |
interface CombinedResponse { | |
updateSubscriptions: UpdateSubscriptionResponse[]; | |
sendNewsletter: SendNewsletterResponse[]; | |
} |
#!/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 { createMiddleware } from '@rescale/nemo'; | |
import { internalMiddleware } from '@/app/(platform)/(personal)/_middleware'; | |
const middlewares = { | |
'/(home|settings){/:path}?': internalMiddleware, | |
}; | |
export const middleware = createMiddleware( | |
middlewares as never, | |
); |
This RFC proposes a new approach to implementing middleware in Next.js, moving away from a single middleware.ts
file to a more dynamic, route-specific implementation similar to the current handling of dynamic segments, pages, and layouts.
The current middleware implementation in Next.js, while powerful, lacks the flexibility and modularity offered by other Next.js features like dynamic routing. This proposal aims to bring middleware in line with these other features, allowing for more granular control and easier management of middleware across a complex application.
#!/bin/bash | |
# Project settings | |
PROJECT_DIR="/opt/projects" # CHANGE PATH | |
# Function to log messages with date and time | |
log_message() { | |
echo "[$(date +"%Y-%m-%d %H:%M:%S")] $1" | |
} |
/** | |
* Smart sorting utility that detects data types and applies appropriate sorting methods | |
* - Strings are compared case-insensitively | |
* - Dates are compared as Date objects | |
* - Numbers are compared numerically | |
* - Booleans are compared as booleans (false first, true second) | |
*/ | |
/** | |
* Detects the data type of a value |