Skip to content

Instantly share code, notes, and snippets.

@milhidaka
Last active July 20, 2022 02:55
Show Gist options
  • Save milhidaka/9984ea6464ec312d2cc51751a9ee50e0 to your computer and use it in GitHub Desktop.
Save milhidaka/9984ea6464ec312d2cc51751a9ee50e0 to your computer and use it in GitHub Desktop.
COEPヘッダ付き開発用HTTPサーバ (SharedArrayBuffer等の検証)
const express = require('express');
const app = express();
const PORT = 8080;
app.use(express.static('public', {
setHeaders: function (res, path) {
// no allow cache
res.set("Cache-Control", "no-cache");
// CORS
res.set("Access-Control-Allow-Origin", "*");
res.set("Access-Control-Allow-Methods", "GET,POST,HEAD,OPTIONS");
// COEP
res.set("Cross-Origin-Embedder-Policy", "require-corp");
res.set("Cross-Origin-Opener-Policy", "same-origin");
}
}));
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`));
{
"name": "sampleserver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "node index.js"
},
"keywords": [],
"author": "",
"license": "CC0",
"devDependencies": {
"express": "^4.18.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment