mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-12 19:40:02 -04:00
Server: switch to Fastify
Switch config to TOML over JSON (it's just nicer TBH)
This commit is contained in:
parent
deda273eda
commit
620ad25c61
20 changed files with 1373 additions and 683 deletions
37
server/serverFactory.ts
Normal file
37
server/serverFactory.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { createServer } from 'node:http';
|
||||
import wisp from 'wisp-server-node';
|
||||
import rammerhead from '@rubynetwork/rammerhead';
|
||||
import { FastifyServerFactory, FastifyServerFactoryHandler, RawServerDefault } from 'fastify';
|
||||
import { parsedDoc } from './config.js';
|
||||
|
||||
const rh = rammerhead.createRammerhead({
|
||||
logLevel: parsedDoc.server.server.logging ? 'debug' : 'disabled',
|
||||
reverseProxy: parsedDoc.server.rammerhead.reverseproxy,
|
||||
disableLocalStorageSync: parsedDoc.server.rammerhead.localstorage_sync ? false : true,
|
||||
disableHttp2: parsedDoc.server.rammerhead.http2 ? false : true
|
||||
});
|
||||
|
||||
const serverFactory: FastifyServerFactory = (handler: FastifyServerFactoryHandler): RawServerDefault => {
|
||||
const httpServer = createServer();
|
||||
httpServer.on('request', (req, res) => {
|
||||
if (rammerhead.shouldRouteRh(req)) {
|
||||
rammerhead.routeRhRequest(rh, req, res);
|
||||
}
|
||||
else {
|
||||
handler(req, res);
|
||||
}
|
||||
});
|
||||
httpServer.on('upgrade', (req, socket, head) => {
|
||||
if (rammerhead.shouldRouteRh(req)) {
|
||||
rammerhead.routeRhUpgrade(rh, req, socket, head);
|
||||
}
|
||||
else if (parsedDoc.server.server.wisp) {
|
||||
if (req.url?.endsWith('/wisp/')) {
|
||||
wisp.routeRequest(req, socket as any, head);
|
||||
}
|
||||
}
|
||||
});
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
export { serverFactory };
|
Loading…
Add table
Add a link
Reference in a new issue