Spaces:
Running
Running
File size: 753 Bytes
46c7a16 |
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 |
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 };
|