-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.js
38 lines (31 loc) · 1.1 KB
/
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
const fastify = require('fastify')()
const path = require('path')
// Headers are required for SharedArrayBuffers and WebAssembly
// Otherwise we wouldn't need a server at all.
function setHeaders(res, path, stat) {
const needsHeaders = path.replaceAll("\\", '/').includes('/emHd') || path.endsWith('index.html');
if (!needsHeaders) return;
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Resource-Policy", "same-site");
}
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'usd-wasm/src'),
prefix: '/usd',
setHeaders,
});
fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
prefix: '/',
setHeaders,
decorateReply: false,
})
fastify.listen({port: process.env.PORT || 3003}, function(err, address) {
if (err) {
fastify.log.error(err);
console.error("Error starting server on port 3003", err);
process.exit(1);
}
console.log(`Your app is listening on ${address}`);
fastify.log.info(`server listening on ${address}`);
});