-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
58 lines (51 loc) · 1.57 KB
/
Copy pathserver.ts
File metadata and controls
58 lines (51 loc) · 1.57 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Rewritten v2 bootstrap:
* - dedicated app factory
* - provider-pluggable analysis
* - single startup path for dev/prod
*/
import dotenv from "dotenv";
import { createServer as createHttpServer } from "http";
import path from "path";
import { fileURLToPath } from "url";
import { createServer as createViteServer } from "vite";
import { createApp } from "./src/server/createApp";
import { SessionRepository } from "./src/server/sessionRepository";
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PORT = Number(process.env.PORT || 3000);
async function startServer() {
const app = createApp({
sessionRepository: new SessionRepository(),
});
const httpServer = createHttpServer(app);
if (process.env.NODE_ENV !== "production") {
const vite = await createViteServer({
server: {
middlewareMode: true,
hmr:
process.env.DISABLE_HMR === "true"
? false
: {
server: httpServer,
clientPort: PORT,
},
},
appType: "spa",
});
app.use(vite.middlewares);
} else {
app.use((await import("express")).default.static(path.join(__dirname, "dist")));
app.get("*", (_req, res) => {
res.sendFile(path.join(__dirname, "dist", "index.html"));
});
}
httpServer.listen(PORT, "0.0.0.0", () => {
console.log(`Interaction Pattern Studio listening on 0.0.0.0:${PORT}`);
});
}
startServer().catch((error) => {
console.error("Fatal startup error:", error);
process.exit(1);
});