Add wisp server node to the server
This commit is contained in:
+19
-3
@@ -1,15 +1,31 @@
|
||||
import Fastify, { FastifyReply, FastifyRequest } from "fastify";
|
||||
import Fastify, { FastifyReply, FastifyRequest, FastifyServerFactory, FastifyServerFactoryHandler, RawServerDefault } from "fastify";
|
||||
import fastifyMiddie from "@fastify/middie";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import wisp from "wisp-server-node";
|
||||
|
||||
//@ts-ignore this is created at runtime. No types associated w/it
|
||||
import { handler as astroHandler } from "../dist/server/entry.mjs";
|
||||
import { createServer } from "node:http";
|
||||
import { Socket } from "node:net";
|
||||
|
||||
const serverFactory: FastifyServerFactory = ( handler: FastifyServerFactoryHandler): RawServerDefault => {
|
||||
return createServer()
|
||||
.on('request', (req, res) => {
|
||||
handler(req, res);
|
||||
})
|
||||
.on('upgrade', (req, socket, head) => {
|
||||
if (req.url?.endsWith('/wisp/')) {
|
||||
wisp.routeRequest(req, socket as Socket, head);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const app = Fastify({
|
||||
logger: true,
|
||||
logger: false,
|
||||
ignoreDuplicateSlashes: true,
|
||||
ignoreTrailingSlash: true
|
||||
ignoreTrailingSlash: true,
|
||||
serverFactory: serverFactory
|
||||
});
|
||||
|
||||
await app.register(fastifyStatic, {
|
||||
|
||||
Reference in New Issue
Block a user