-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.ts
More file actions
43 lines (37 loc) · 1.23 KB
/
server.ts
File metadata and controls
43 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import express from "express";
import aiRouter from "./server/ai.controller.js";
import path from "path";
import { fileURLToPath } from "url";
import { serverRegistry } from "./tools/registry.server.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(express.json({ limit: "500mb" }));
// don't set compression this is effecting the streaming of the data
// Serve static files from dist directory with caching
app.use(
express.static(path.join(__dirname, "../dist"), {
// Built-in Express static file options
setHeaders: (res, path) => {
if (path.match(/\.(jpg|jpeg|png|gif|ico|svg|webp)$/i)) {
// Cache for 1 week
res.set("Cache-Control", "public, max-age=604800, immutable");
}
},
})
);
// API routes
app.use("/api/ai", aiRouter);
app.use("/api/tools", serverRegistry.getRouter());
// Serve index.html for all other routes (SPA support)
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "../dist", "index.html"));
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(
`Server running on http://localhost:${PORT} in ${
process.env.NODE_ENV || "development"
} mode`
);
});