- limit login attempts per IP (5 per 15 min by default, counted before the password check so parallel requests cannot exceed it), 429 + Retry-After, failed logins logged with the client IP - TRUSTED_PROXIES env to honour X-Forwarded-For from the reverse proxy only - changing or regenerating a group password closes that group's other sessions; deleting a group closes all of its sessions - new group passwords: 12 to 256 characters and not shared with another group (login opens the first matching group) - PATCH /groups/:id/password no longer echoes the password - purge expired sessions every 10 minutes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1 KiB
JavaScript
32 lines
1 KiB
JavaScript
import express from "express";
|
|
import path from "node:path";
|
|
import { config } from "./config.js";
|
|
import { requireAdmin, requireAuth } from "./middlewares/auth.js";
|
|
import { adminRouter } from "./routes/admin.js";
|
|
import { authRouter } from "./routes/auth.js";
|
|
import { logsRouter } from "./routes/logs.js";
|
|
import { serversRouter } from "./routes/servers.js";
|
|
|
|
function createApp() {
|
|
const app = express();
|
|
if (config.trustedProxies.length) {
|
|
app.set("trust proxy", config.trustedProxies);
|
|
}
|
|
app.use(express.json());
|
|
app.get("/healthz", (_req, res) => res.json({ ok: true }));
|
|
app.use("/server-images", express.static(config.serverImagesDir));
|
|
|
|
app.use("/api", authRouter);
|
|
app.use("/api", requireAuth, serversRouter);
|
|
app.use("/api", requireAuth, requireAdmin, logsRouter);
|
|
app.use("/api/admin", requireAuth, requireAdmin, adminRouter);
|
|
|
|
app.use(express.static(config.publicDir));
|
|
app.get("/{*splat}", (_req, res) => {
|
|
res.sendFile(path.join(config.publicDir, "index.html"));
|
|
});
|
|
|
|
return app;
|
|
}
|
|
|
|
export { createApp };
|