- Move SuperTokens.init() to runtime (not build time) - Add dynamic route config to prevent build-time evaluation - Move appInfo inside backendConfig function - Update default URLs to vibnai.com Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import SuperTokens from "supertokens-node";
|
|
import { backendConfig } from "@/lib/supertokens/backendConfig";
|
|
import { getAppDirRequestHandler } from "supertokens-node/nextjs";
|
|
|
|
// Tell Next.js this is a dynamic route (don't evaluate at build time)
|
|
export const dynamic = 'force-dynamic';
|
|
export const runtime = 'nodejs';
|
|
|
|
// Initialize SuperTokens lazily (only when first request comes in)
|
|
let initialized = false;
|
|
|
|
function ensureInitialized() {
|
|
if (!initialized && typeof window === 'undefined') {
|
|
SuperTokens.init(backendConfig());
|
|
initialized = true;
|
|
}
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|
|
|
|
export async function DELETE(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|
|
|
|
export async function PUT(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|
|
|
|
export async function PATCH(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|
|
|
|
export async function HEAD(request: NextRequest) {
|
|
ensureInitialized();
|
|
const handleRequest = getAppDirRequestHandler(NextResponse);
|
|
const response = await handleRequest(request);
|
|
return response;
|
|
}
|