This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import express from 'express';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import express from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default async function webserver() {
|
||||
const app = express();
|
||||
@@ -8,13 +8,15 @@ export default async function webserver() {
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
const webDir = path.join(__dirname, 'web');
|
||||
const webDir = path.join(__dirname, "web");
|
||||
if (fs.existsSync(webDir)) {
|
||||
const files = fs.readdirSync(webDir).filter(f => f.endsWith('.ts') || f.endsWith('.js'));
|
||||
const files = fs
|
||||
.readdirSync(webDir)
|
||||
.filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
|
||||
for (const file of files) {
|
||||
const mod = await import(path.join(webDir, file));
|
||||
const handler = mod.default ?? mod;
|
||||
if (typeof handler === 'function') {
|
||||
if (typeof handler === "function") {
|
||||
await handler(app);
|
||||
console.log(`[WEB] Loaded web route: ${file}`);
|
||||
}
|
||||
@@ -25,7 +27,7 @@ export default async function webserver() {
|
||||
console.log(`[WEB] Web server is running on port ${PORT}`);
|
||||
});
|
||||
|
||||
const IgnoredPaths = ['/favicon.ico', '/robots.txt', "/", "/hello"];
|
||||
const IgnoredPaths = ["/favicon.ico", "/robots.txt", "/", "/hello"];
|
||||
const KnownPaths = ["/git-commit", "/", "/health"];
|
||||
|
||||
// log all incoming requests
|
||||
@@ -34,10 +36,14 @@ export default async function webserver() {
|
||||
return next();
|
||||
}
|
||||
if (!KnownPaths.includes(req.url)) {
|
||||
console.warn(`[WEB] Unknown Route request: ${req.method} ${req.url} {${req.ip}}`);
|
||||
console.warn(
|
||||
`[WEB] Unknown Route request: ${req.method} ${req.url} {${req.ip}}`,
|
||||
);
|
||||
} else {
|
||||
console.log(`[WEB] Trusted Route request: ${req.method} ${req.url} {${req.ip}}`);
|
||||
console.log(
|
||||
`[WEB] Trusted Route request: ${req.method} ${req.url} {${req.ip}}`,
|
||||
);
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user