maybe fix it?
This commit is contained in:
parent
ca37615bef
commit
7b273166ed
1 changed files with 58 additions and 58 deletions
116
index.js
116
index.js
|
|
@ -19,64 +19,6 @@ const bare = createBareServer("/bare/");
|
||||||
console.log(chalk.gray("Starting Bare..."));
|
console.log(chalk.gray("Starting Bare..."));
|
||||||
console.log(chalk.gray("Starting Rammerhead..."));
|
console.log(chalk.gray("Starting Rammerhead..."));
|
||||||
|
|
||||||
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"
|
|
||||||
];
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
let server = createServer();
|
|
||||||
server.on("request", (req, res) => {
|
|
||||||
if (bare.shouldRoute(req)) {
|
|
||||||
bare.routeRequest(req, res);
|
|
||||||
} else if (shouldRouteRh(req)) {
|
|
||||||
routeRhRequest(req, res);
|
|
||||||
} else {
|
|
||||||
app(req, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("upgrade", (req, socket, head) => {
|
|
||||||
if (bare.shouldRoute(req)) {
|
|
||||||
bare.routeUpgrade(req, socket, head);
|
|
||||||
} else if (shouldRouteRh(req)) {
|
|
||||||
routeRhUpgrade(req, socket, head);
|
|
||||||
} else {
|
|
||||||
socket.end();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
app.use(express.static(path.join(process.cwd(), "static")));
|
app.use(express.static(path.join(process.cwd(), "static")));
|
||||||
|
|
@ -106,6 +48,64 @@ app.get("*", function (req, res) {
|
||||||
res.redirect(302, "/404.html");
|
res.redirect(302, "/404.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
];
|
||||||
|
const rammerheadSession = /^\/[a-z0-9]{32}/;
|
||||||
|
|
||||||
|
let server = createServer();
|
||||||
|
server.on("request", (req, res) => {
|
||||||
|
if (bare.shouldRoute(req)) {
|
||||||
|
bare.routeRequest(req, res);
|
||||||
|
} else if (shouldRouteRh(req)) {
|
||||||
|
routeRhRequest(req, res);
|
||||||
|
} else {
|
||||||
|
app(req, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on("upgrade", (req, socket, head) => {
|
||||||
|
if (bare.shouldRoute(req)) {
|
||||||
|
bare.routeUpgrade(req, socket, head);
|
||||||
|
} else if (shouldRouteRh(req)) {
|
||||||
|
routeRhUpgrade(req, socket, head);
|
||||||
|
} else {
|
||||||
|
socket.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(chalk.gray("Starting Alu..."));
|
console.log(chalk.gray("Starting Alu..."));
|
||||||
console.log(chalk.green("Alu started successfully!"));
|
console.log(chalk.green("Alu started successfully!"));
|
||||||
server.on("listening", () => {
|
server.on("listening", () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue