-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
38 lines (32 loc) · 987 Bytes
/
main.ts
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
// @deno-types="npm:@types/express@4"
import express from "npm:[email protected]";
// @deno-types="npm:@types/express-actuator@1"
import actuator from "npm:[email protected]";
import { router as index } from "./routes/index.ts";
import { router as todo } from "./routes/todo.ts";
import { migrate } from "./utils/sqlite.ts";
migrate();
const app = express();
app.use(express.json());
app.use(express.urlencoded({
extended: true,
}));
app.use(actuator());
app.use(index);
app.use("/items", todo);
const port = Number(Deno.env.get("PORT")) || 3000;
const server = app.listen(port, () => {
console.debug(`Listening on ${server.address().port} ...`);
});
addEventListener("unload", () => {
console.debug("closing HTTP server");
server.close(() => {
console.debug("HTTP server closed");
});
});
addEventListener("SIGTERM", () => {
console.debug("SIGTERM signal received: closing HTTP server");
server.close(() => {
console.debug("HTTP server closed");
});
});