fortnite sauce

This commit is contained in:
st5 committed 2026-04-04 12:28:36 -05:00
1 parent 649574ec11
commit 25dd6281ce
6 files changed
+400 -968

No files matched your search

+30 -81
View File
@@ -1,45 +1,10 @@
const http = require("http");
const fs = require("fs");
const path = require("path");
const { createLogger, format, transports } = require("winston");
const { consoleFormat } = require("winston-console-format");
const util = require("util");
const { readFile, stat } = require("fs");
const { extname, join, normalize } = require("path");
const logger = createLogger({
level: "silly",
format: format.combine(
format.timestamp(),
format.ms(),
format.errors({ stack: true }),
format.splat(),
format.json()
),
defaultMeta: { service: "Test" },
transports: [
new transports.Console({
format: format.combine(
format.colorize({ all: true }),
format.padLevels(),
consoleFormat({
showMeta: true,
metaStrip: ["timestamp", "service"],
inspectOptions: {
depth: Infinity,
colors: true,
maxArrayLength: Infinity,
breakLength: 120,
compact: Infinity,
},
})
),
}),
],
});
const PORT = process.env.PORT || 3000;
const PUBLIC_DIR = path.join(__dirname, "public");
const MIME_TYPES = {
const port = process.env.PORT || 3000;
const public_dir = join(__dirname, "public");
const mime_types = {
".html": "text/html; charset=UTF-8",
".css": "text/css; charset=UTF-8",
".js": "application/javascript; charset=UTF-8",
@@ -54,51 +19,35 @@ const MIME_TYPES = {
".ico": "image/x-icon"
};
function resolveFilePath(urlPath) {
if (!urlPath || urlPath === "/") {
return path.join(PUBLIC_DIR, "index.html");
}
const safe_path = (url_path) => {
if (!url_path || url_path === "/") return join(public_dir, "index.html");
const cleaned = normalize(url_path).replace(/^(\.\.([/\\]|$))+/, "");
return join(public_dir, cleaned);
};
const safePath = path.normalize(urlPath).replace(/^(\.\.([/\\]|$))+/, "");
return path.join(PUBLIC_DIR, safePath);
}
function sendFile(filePath, res) {
fs.readFile(filePath, (err, data) => {
if (err) {
if (err.code === "ENOENT") {
res.writeHead(404, { "Content-Type": "text/plain; charset=UTF-8" });
res.end("404 Not Found");
return;
}
res.writeHead(500, { "Content-Type": "text/plain; charset=UTF-8" });
res.end("500 Internal Server Error");
const send = (file_path, res) => {
readFile(file_path, (err, data) => {
if (err?.code === "ENOENT") {
res.writeHead(404, { "Content-Type": "text/plain; charset=UTF-8" });
res.end("404 not found");
return;
}
const ext = path.extname(filePath).toLowerCase();
const contentType = MIME_TYPES[ext] || "application/octet-stream";
res.writeHead(200, { "Content-Type": contentType });
if (err) {
res.writeHead(500, { "Content-Type": "text/plain; charset=UTF-8" });
res.end("500 internal server error");
return;
}
const type = mime_types[extname(file_path).toLowerCase()] || "application/octet-stream";
res.writeHead(200, { "Content-Type": type });
res.end(data);
});
}
};
const server = http.createServer((req, res) => {
const reqPath = (req.url || "/").split("?")[0];
const filePath = resolveFilePath(reqPath);
fs.stat(filePath, (err, stat) => {
if (!err && stat.isDirectory()) {
sendFile(path.join(filePath, "index.html"), res);
return;
}
sendFile(filePath, res);
http
.createServer((req, res) => {
const file_path = safe_path((req.url || "/").split("?")[0]);
stat(file_path, (err, info) => send(!err && info.isDirectory() ? join(file_path, "index.html") : file_path, res));
})
.listen(port, () => {
console.log(`web running at http://localhost:${port}`);
});
});
server.listen(PORT, () => {
logger.info(`web running at http://localhost:${PORT}`);
});