-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (30 loc) · 878 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
const Koa = require("koa");
const static = require("koa-static");
const range = require("koa-range");
const path = require("path");
const port = parseInt(process.env.PORT, 10) || 3000;
const server = new Koa();
server.use(async (ctx, next) => {
ctx.res.statusCode = 200;
await next();
});
server.use(range);
server.use(
static(path.join(__dirname, "pdf"), {
maxage: 30 * 24 * 60 * 60 * 1000,
setHeaders: function (res) {
res.setHeader("Accept-Ranges", "bytes");
res.setHeader("Access-Control-Allow-Headers", "Range");
res.setHeader("Access-Control-Expose-Headers", "Accept-Ranges");
res.setHeader("Access-Control-Allow-Origin", "*");
},
})
);
server.use(
static(path.join(__dirname, "demo"), {
maxage: 30 * 24 * 60 * 60 * 1000,
})
);
server.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`);
});