Add subtle interface polish and clean URLs
This commit is contained in:
1 parent
3575a35877
commit
39407585f2
8 files changed
+338
-40
No files matched your search
@@ -70,6 +70,18 @@ const MIME = {
|
||||
".woff2": "font/woff2"
|
||||
};
|
||||
|
||||
const CLEAN_ROUTES = {
|
||||
"/techday": "/techday.html",
|
||||
"/gamejam": "/gamejam.html",
|
||||
"/impressum": "/impressum.html",
|
||||
"/datenschutz": "/datenschutz.html"
|
||||
};
|
||||
|
||||
function redirect(res, location) {
|
||||
res.writeHead(308, { Location: location });
|
||||
res.end();
|
||||
}
|
||||
|
||||
/* ---------- Lead-Speicher vorbereiten ---------- */
|
||||
function ensureLeadStore() {
|
||||
if (!fs.existsSync(LEADS_DIR)) fs.mkdirSync(LEADS_DIR, { recursive: true });
|
||||
@@ -112,9 +124,31 @@ function saveLead(lead) {
|
||||
|
||||
/* ---------- Statische Dateien ---------- */
|
||||
function serveStatic(req, res) {
|
||||
let urlPath = decodeURIComponent(req.url.split("?")[0]);
|
||||
let parsedUrl;
|
||||
try {
|
||||
parsedUrl = new URL(req.url, "http://local");
|
||||
} catch (e) {
|
||||
res.writeHead(400).end("Bad Request");
|
||||
return;
|
||||
}
|
||||
|
||||
let urlPath = decodeURIComponent(parsedUrl.pathname);
|
||||
if (urlPath === "/") urlPath = "/index.html";
|
||||
|
||||
if (urlPath.endsWith("/") && CLEAN_ROUTES[urlPath.slice(0, -1)]) {
|
||||
redirect(res, urlPath.slice(0, -1) + parsedUrl.search);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const cleanPath of Object.keys(CLEAN_ROUTES)) {
|
||||
if (urlPath === CLEAN_ROUTES[cleanPath]) {
|
||||
redirect(res, cleanPath + parsedUrl.search);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (CLEAN_ROUTES[urlPath]) urlPath = CLEAN_ROUTES[urlPath];
|
||||
|
||||
/* Path-Traversal verhindern */
|
||||
const filePath = path.normalize(path.join(PUBLIC_DIR, urlPath));
|
||||
if (!filePath.startsWith(PUBLIC_DIR)) {
|
||||
|
||||
Reference in new issue
Block a user