forked from Stremio/stremio-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_server.js
executable file
·56 lines (49 loc) · 1.81 KB
/
http_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
// Copyright (C) 2017-2023 Smart code 203358507
// const INDEX_CACHE = 7200;
// const ASSETS_CACHE = 2629744;
// const HTTP_PORT = 8080;
//
// const express = require('express');
// const path = require('path');
//
// const build_path = path.resolve(__dirname, 'build');
// const index_path = path.join(build_path, 'index.html');
//
// const app = express();
//
// // Set Content Security Policy header
// app.use((req, res, next) => {
// res.set('Content-Security-Policy', "default-src 'self' https:; img-src 'self' http: https:; script-src 'self' http: https:; upgrade-insecure-requests");
// next();
// });
//
// app.use(express.static(build_path, {
// setHeaders: (res, path) => {
// if (path === index_path) res.set('cache-control', `public, max-age: ${INDEX_CACHE}`);
// else res.set('cache-control', `public, max-age: ${ASSETS_CACHE}`);
// }
// }));
//
// app.all('*', (_req, res) => {
// // TODO: better 404 page
// res.status(404).send('<h1>404! Page not found</h1>');
// });
//
// app.listen(HTTP_PORT, () => console.info(`Server listening on port: ${HTTP_PORT}`));
const INDEX_CACHE = 7200;
const ASSETS_CACHE = 2629744;
const HTTP_PORT = 8080;
const express = require('express');
const path = require('path');
const build_path = path.resolve(__dirname, 'build');
const index_path = path.join(build_path, 'index.html');
express().use(express.static(build_path, {
setHeaders: (res, path) => {
if (path === index_path) res.set('cache-control', `public, max-age: ${INDEX_CACHE}`);
else res.set('cache-control', `public, max-age: ${ASSETS_CACHE}`);
}
})).all('*', (_req, res) => {
// TODO: better 404 page
res.status(404).send('<h1>404! Page not found</h1>');
}).listen(HTTP_PORT, () => console.info(`Server listening on port: ${HTTP_PORT}`));