mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-13 12:00:01 -04:00
.
This commit is contained in:
parent
a62534618b
commit
06d02c42f1
18 changed files with 9778 additions and 0 deletions
23
server/serverFactory.js
Normal file
23
server/serverFactory.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { createServer } from "node:http";
|
||||
import wisp from "wisp-server-node";
|
||||
import { LOG_LEVEL } from "wisp-server-node/dist/Types.js";
|
||||
import { parsedDoc } from "./config.js";
|
||||
const wispOptions = {
|
||||
logLevel: parsedDoc.server.server.logging ? LOG_LEVEL.DEBUG : LOG_LEVEL.NONE,
|
||||
pingInterval: 30
|
||||
};
|
||||
const serverFactory = (handler) => {
|
||||
const httpServer = createServer();
|
||||
httpServer.on("request", (req, res) => {
|
||||
handler(req, res);
|
||||
});
|
||||
httpServer.on("upgrade", (req, socket, head) => {
|
||||
if (parsedDoc.server.server.wisp) {
|
||||
if (req.url?.endsWith("/wisp/")) {
|
||||
wisp.routeRequest(req, socket, head, wispOptions);
|
||||
}
|
||||
}
|
||||
});
|
||||
return httpServer;
|
||||
};
|
||||
export { serverFactory };
|
Loading…
Add table
Add a link
Reference in a new issue