Incognito3 / server /serverFactory.ts
Alex Scott
rebrand space to incognito
46c7a16
raw
history blame contribute delete
753 Bytes
import { createServer } from 'node:http';
import { Socket } from 'node:net';
import {
type FastifyServerFactory,
FastifyServerFactoryHandler,
RawServerDefault,
} from 'npm:fastify';
import wisp from 'npm:wisp-server-node';
import { parsedDoc } from './config/config.ts';
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/') && parsedDoc.server.wisp === true) {
wisp.routeRequest(req, socket as Socket, head);
}
});
};
export { serverFactory };