Skip to content

Commit ad3bae7

Browse files
rsbhclaude
andcommitted
feat: add Vercel serverless function entry point
Exports a Node.js handler that delegates to the shared request handler for SSR + API routes on Vercel. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ba09eea commit ad3bae7

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Vercel serverless function entry — built by Vite, deployed as catch-all function
2+
import type { IncomingMessage, ServerResponse } from 'http'
3+
import { readFileSync } from 'fs'
4+
import path from 'path'
5+
import { handleRequest } from './request-handler'
6+
7+
const templatePath = path.resolve(__dirname, 'index.html')
8+
const template = readFileSync(templatePath, 'utf-8')
9+
10+
export default async function handler(req: IncomingMessage, res: ServerResponse) {
11+
const url = req.url || '/'
12+
const baseUrl = `https://${req.headers.host || 'localhost'}`
13+
14+
try {
15+
const response = await handleRequest(url, { template, baseUrl })
16+
17+
res.statusCode = response.status
18+
response.headers.forEach((value: string, key: string) => res.setHeader(key, value))
19+
const body = await response.text()
20+
res.end(body)
21+
} catch (e) {
22+
console.error(e)
23+
res.statusCode = 500
24+
res.end((e as Error).message)
25+
}
26+
}

0 commit comments

Comments
 (0)