mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-13 20:10:01 -04:00
Prettier Format
This commit is contained in:
parent
3a9024d1e0
commit
ad67368a45
42 changed files with 1650 additions and 1609 deletions
172
server.ts
172
server.ts
|
@ -1,86 +1,86 @@
|
|||
import fastify from 'fastify';
|
||||
import fastifyStatic from '@fastify/static';
|
||||
import { fileURLToPath } from 'url';
|
||||
import path from 'path';
|
||||
import createRammerhead from "rammerhead/src/server/index.js";
|
||||
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||
import { createServer } from "http";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const bare = createBareServer("/bare/");
|
||||
const rh = createRammerhead();
|
||||
|
||||
const rammerheadScopes = [
|
||||
"/rammerhead.js",
|
||||
"/hammerhead.js",
|
||||
"/transport-worker.js",
|
||||
"/task.js",
|
||||
"/iframe-task.js",
|
||||
"/worker-hammerhead.js",
|
||||
"/messaging",
|
||||
"/sessionexists",
|
||||
"/deletesession",
|
||||
"/newsession",
|
||||
"/editsession",
|
||||
"/needpassword",
|
||||
"/syncLocalStorage",
|
||||
"/api/shuffleDict",
|
||||
"/mainport"
|
||||
];
|
||||
|
||||
const rammerheadSession = /^\/[a-z0-9]{32}/;
|
||||
|
||||
function shouldRouteRh(req) {
|
||||
const url = new URL(req.url, "http://0.0.0.0");
|
||||
return (
|
||||
rammerheadScopes.includes(url.pathname) ||
|
||||
rammerheadSession.test(url.pathname)
|
||||
);
|
||||
}
|
||||
|
||||
function routeRhRequest(req, res) {
|
||||
rh.emit("request", req, res);
|
||||
}
|
||||
|
||||
function routeRhUpgrade(req, socket, head) {
|
||||
rh.emit("upgrade", req, socket, head);
|
||||
}
|
||||
|
||||
const serverFactory = (handler, opts) => {
|
||||
return createServer()
|
||||
.on("request", (req, res) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeRequest(req, res);
|
||||
} else if (shouldRouteRh(req)) {
|
||||
routeRhRequest(req, res);
|
||||
} else {
|
||||
handler(req, res);
|
||||
}
|
||||
})
|
||||
.on("upgrade", (req, socket, head) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeUpgrade(req, socket, head);
|
||||
} else if (shouldRouteRh(req)) {
|
||||
routeRhUpgrade(req, socket, head);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const app = fastify({ logger: true, serverFactory });
|
||||
|
||||
app.register(fastifyStatic, {
|
||||
root: path.join(__dirname, 'dist'),
|
||||
prefix: '/',
|
||||
serve: true,
|
||||
wildcard: false,
|
||||
});
|
||||
|
||||
app.setNotFoundHandler((req, res) => {
|
||||
res.sendFile('index.html') // SPA catch-all
|
||||
})
|
||||
|
||||
app.listen({
|
||||
port: 8080
|
||||
});
|
||||
import fastify from "fastify";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import { fileURLToPath } from "url";
|
||||
import path from "path";
|
||||
import createRammerhead from "rammerhead/src/server/index.js";
|
||||
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||
import { createServer } from "http";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const bare = createBareServer("/bare/");
|
||||
const rh = createRammerhead();
|
||||
|
||||
const rammerheadScopes = [
|
||||
"/rammerhead.js",
|
||||
"/hammerhead.js",
|
||||
"/transport-worker.js",
|
||||
"/task.js",
|
||||
"/iframe-task.js",
|
||||
"/worker-hammerhead.js",
|
||||
"/messaging",
|
||||
"/sessionexists",
|
||||
"/deletesession",
|
||||
"/newsession",
|
||||
"/editsession",
|
||||
"/needpassword",
|
||||
"/syncLocalStorage",
|
||||
"/api/shuffleDict",
|
||||
"/mainport"
|
||||
];
|
||||
|
||||
const rammerheadSession = /^\/[a-z0-9]{32}/;
|
||||
|
||||
function shouldRouteRh(req) {
|
||||
const url = new URL(req.url, "http://0.0.0.0");
|
||||
return (
|
||||
rammerheadScopes.includes(url.pathname) ||
|
||||
rammerheadSession.test(url.pathname)
|
||||
);
|
||||
}
|
||||
|
||||
function routeRhRequest(req, res) {
|
||||
rh.emit("request", req, res);
|
||||
}
|
||||
|
||||
function routeRhUpgrade(req, socket, head) {
|
||||
rh.emit("upgrade", req, socket, head);
|
||||
}
|
||||
|
||||
const serverFactory = (handler, opts) => {
|
||||
return createServer()
|
||||
.on("request", (req, res) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeRequest(req, res);
|
||||
} else if (shouldRouteRh(req)) {
|
||||
routeRhRequest(req, res);
|
||||
} else {
|
||||
handler(req, res);
|
||||
}
|
||||
})
|
||||
.on("upgrade", (req, socket, head) => {
|
||||
if (bare.shouldRoute(req)) {
|
||||
bare.routeUpgrade(req, socket, head);
|
||||
} else if (shouldRouteRh(req)) {
|
||||
routeRhUpgrade(req, socket, head);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const app = fastify({ logger: true, serverFactory });
|
||||
|
||||
app.register(fastifyStatic, {
|
||||
root: path.join(__dirname, "dist"),
|
||||
prefix: "/",
|
||||
serve: true,
|
||||
wildcard: false
|
||||
});
|
||||
|
||||
app.setNotFoundHandler((req, res) => {
|
||||
res.sendFile("index.html"); // SPA catch-all
|
||||
});
|
||||
|
||||
app.listen({
|
||||
port: 8080
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue