-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
40 lines (32 loc) · 1 KB
/
server.ts
File metadata and controls
40 lines (32 loc) · 1 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
import "dotenv/config";
import { createServer } from "http";
import { parse } from "url";
import next from "next";
import { initSocketServer } from "./server/socket";
const dev = process.env.NODE_ENV !== "production";
const port = Number(process.env.PORT ?? 3000);
const hostname = process.env.HOSTNAME ?? "0.0.0.0";
async function bootstrap() {
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
await app.prepare();
const server = createServer((req, res) => {
if (!req.url) {
res.statusCode = 400;
res.end("Bad Request");
return;
}
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
});
initSocketServer(server);
server.listen(port, hostname, () => {
// eslint-disable-next-line no-console
console.log(`ScribeAI server running on http://${hostname}:${port}`);
});
}
bootstrap().catch((error) => {
// eslint-disable-next-line no-console
console.error("Failed to start server", error);
process.exit(1);
});