-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
29 lines (25 loc) · 791 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import FastifyVite from '@fastify/vite'
import { createRequest, sendResponse } from '@mjackson/node-fetch-server'
import { handleFetch$, hasHandler, fetch$ } from '@tanstack/bling/server'
import fastify from 'fastify'
import renderer from 'uma/renderer'
const app = fastify({
logger: true,
})
await app.register(FastifyVite, {
root: import.meta.url,
renderer: renderer as any,
})
app.addHook('onRequest', async (req, res) => {
if (!req.url.startsWith('/_m')) return
const request = createRequest(req.raw, res.raw, { host: req.host })
if (hasHandler(new URL(request.url).pathname)) {
const response = await handleFetch$({
request: request,
})
await sendResponse(res.raw, response)
res.end()
}
})
await app.vite.ready()
await app.listen({ port: 3000 })