mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
some styling cleanup
This commit is contained in:
@@ -3,28 +3,39 @@ const path = require("path");
|
||||
const config = require("./config");
|
||||
const { setupWebSocket } = require("./ws");
|
||||
|
||||
const ANSI_RED = "\x1b[31m";
|
||||
const ANSI_YELLOW = "\x1b[33m";
|
||||
const ANSI_GREEN = "\x1b[32m";
|
||||
const ANSI_RESET = "\x1b[0m";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
|
||||
// logger middleware
|
||||
app.use((req, res, next) => {
|
||||
const start = Date.now();
|
||||
const origEnd = res.end;
|
||||
|
||||
res.end = function (...args) {
|
||||
const duration = Date.now() - start;
|
||||
const status = res.statusCode;
|
||||
|
||||
const color =
|
||||
status >= 500 ? "\x1b[31m" : status >= 400 ? "\x1b[33m" : "\x1b[32m";
|
||||
const reset = "\x1b[0m";
|
||||
status >= 500 ? ANSI_RED : status >= 400 ? ANSI_YELLOW : ANSI_GREEN;
|
||||
|
||||
const path =
|
||||
req.originalUrl.length > 80
|
||||
? req.originalUrl.slice(0, 80) + "..."
|
||||
: req.originalUrl;
|
||||
|
||||
console.log(
|
||||
`${color}${req.method} ${status}${reset} ${path} (${duration}ms)`,
|
||||
`${color}${req.method} ${status}${ANSI_RESET} ${path} (${duration}ms)`,
|
||||
);
|
||||
|
||||
origEnd.apply(this, args);
|
||||
};
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -41,11 +52,18 @@ app.use("/api/proxy", proxyRoutes);
|
||||
app.use("/vault-files", (req, res, next) => {
|
||||
// Extract vault ID from the first path segment
|
||||
const parts = req.path.split("/").filter(Boolean);
|
||||
if (parts.length === 0)
|
||||
|
||||
if (parts.length === 0) {
|
||||
return res.status(400).json({ error: "Missing vault ID" });
|
||||
}
|
||||
|
||||
const vaultId = decodeURIComponent(parts[0]);
|
||||
const vaultPath = config.getVaultPath(vaultId);
|
||||
if (!vaultPath) return res.status(404).json({ error: "Vault not found" });
|
||||
|
||||
if (!vaultPath) {
|
||||
return res.status(404).json({ error: "Vault not found" });
|
||||
}
|
||||
|
||||
// Rewrite req.url to strip the vault ID prefix, then serve statically
|
||||
req.url = "/" + parts.slice(1).join("/");
|
||||
express.static(vaultPath)(req, res, next);
|
||||
|
||||
Reference in New Issue
Block a user