stremio-web/http_server.js
2024-04-20 17:08:49 +00:00

26 lines
976 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}`);
// allow using a streaming server URL that uses http, like for when hosting a streaming server on a local network
res.set('Content-Security-Policy', 'upgrade-insecure-requests');
}
})).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}`));