-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·42 lines (36 loc) · 872 Bytes
/
server.js
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
#!/usr/bin/env node
import Koa from "koa";
import serve from "koa-static";
import render from "@koa/ejs";
import { bodyParser } from "@koa/bodyparser";
import { router } from "./src/routes.js";
import { BIND, PORT, LIMIT_SIZE } from "./src/constants.js";
const app = new Koa();
const { dirname } = import.meta;
// static server
app.use(
serve(`${dirname}/static`, {
maxAge: 2592000 * 1000, // 30d in milliseconds
})
);
// views
render(app, {
root: `${dirname}/src/views`,
layout: "_layout",
});
// parse form files
app.use(
bodyParser({
enableTypes: ["form", "text", "json", "xml"],
formLimit: LIMIT_SIZE,
textLimit: LIMIT_SIZE,
jsonLimit: LIMIT_SIZE,
xmlLimit: LIMIT_SIZE,
})
);
// routes
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(PORT, () => {
console.log(`Listen on http://${BIND}:${PORT}`);
});