-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdocker-static-server.js
More file actions
50 lines (44 loc) · 1.66 KB
/
Copy pathdocker-static-server.js
File metadata and controls
50 lines (44 loc) · 1.66 KB
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
/**
* Minimal production static file server for the Ontosphere Docker image.
*
* Sets Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers
* so that SharedArrayBuffer is available, which the Konclude WASM reasoner
* requires (https://developer.chrome.com/blog/enabling-shared-array-buffer).
*
* Usage (inside container): node docker-static-server.js
* Direct usage: PORT=8080 node docker-static-server.js
*/
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express();
const PORT = process.env.PORT || 8080;
const DIST = path.join(__dirname, 'dist');
// Cross-origin isolation headers — required for SharedArrayBuffer (WASM pthreads).
app.use((_req, res, next) => {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'credentialless');
next();
});
// Serve built assets with long-lived cache (Vite hashes file names).
app.use(
express.static(DIST, {
maxAge: '1y',
immutable: true,
// Do not set cache for the entry-point HTML itself.
setHeaders(res, filePath) {
if (filePath.endsWith('.html')) {
res.setHeader('Cache-Control', 'no-cache');
}
},
}),
);
// SPA fallback — all unknown GET paths serve index.html so client-side routing works.
app.get('*', (_req, res) => {
res.sendFile(path.join(DIST, 'index.html'));
});
app.listen(PORT, () => {
console.log(`Ontosphere static server listening on http://localhost:${PORT}`);
console.log('Cross-origin isolation headers (COOP/COEP) active — WASM reasoner will work.');
});