mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-01-11 22:40:31 +00:00
Custom HTTP server for proper cache headers
This commit is contained in:
parent
b1f9abb0c9
commit
361ba354cb
2 changed files with 24 additions and 2 deletions
|
|
@ -14,7 +14,6 @@ RUN mkdir -p /var/www/stremio-web
|
|||
WORKDIR /var/www/stremio-web
|
||||
COPY . /var/www/stremio-web
|
||||
RUN npm install
|
||||
RUN npm install -g http-server
|
||||
|
||||
# Bundle app source
|
||||
WORKDIR /var/www/stremio-web
|
||||
|
|
@ -22,4 +21,4 @@ WORKDIR /var/www/stremio-web
|
|||
RUN npm run build
|
||||
|
||||
EXPOSE 8080
|
||||
CMD ["http-server", "/var/www/stremio-web/build/", "-p", "8080", "-d", "false"]
|
||||
CMD ["node", "http_server.js"]
|
||||
|
|
|
|||
23
http_server.js
Executable file
23
http_server.js
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Copyright (C) 2017-2023 Smart code 203358507
|
||||
|
||||
const INDEX_CACHE = 1600;
|
||||
const ASSETS_CACHE = 3600;
|
||||
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: function(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}`));
|
||||
Loading…
Reference in a new issue