Spaces:
Running
Running
Download scripts/serve.mjs from davanstrien/phonon-reader: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/davanstrien/phonon-reader/resolve/main/scripts/serve.mjs
- Command line
-
hf download hf://spaces/davanstrien/phonon-reader/scripts/serve.mjs
-
curl -L -o serve.mjs https://huggingface.co/spaces/davanstrien/phonon-reader/resolve/main/scripts/serve.mjs
1 kB
| // Local test server for dist/ with the cross-origin isolation headers. | |
| import { createServer } from 'node:http'; | |
| import { readFile } from 'node:fs/promises'; | |
| import { join, extname } from 'node:path'; | |
| const dist = new URL('../dist/', import.meta.url).pathname; | |
| const types = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.wasm': 'application/wasm', '.png': 'image/png', '.webmanifest': 'application/manifest+json' }; | |
| createServer(async (req, res) => { | |
| let p = decodeURIComponent(new URL(req.url, 'http://x').pathname); | |
| if (p.endsWith('/')) p += 'index.html'; | |
| try { | |
| const body = await readFile(join(dist, p)); | |
| res.writeHead(200, { 'Content-Type': types[extname(p)] || 'application/octet-stream', | |
| 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp' }); | |
| res.end(body); | |
| } catch { res.writeHead(404); res.end(); } | |
| }).listen(process.env.PORT || 4173, () => console.log('serving dist on', process.env.PORT || 4173)); | |