stremio-web/http_server.js
2023-06-08 13:01:10 +03:00

23 lines
780 B
JavaScript
Executable file

#!/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');
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}`));