|
|
@@ -25,6 +25,11 @@ try { events = JSON.parse(await readFile(STORE, "utf8")); } catch { }
|
|
|
async function persist() { try { await writeFile(STORE, JSON.stringify(events.slice(-MAX)), "utf8"); } catch { } }
|
|
|
|
|
|
const server = http.createServer(async (req, res) => {
|
|
|
+ /* CORS:允许门户(file://页面,origin=null)跨域轮询;鉴权仍由token控制 */
|
|
|
+ res.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ res.setHeader("Access-Control-Allow-Headers", "content-type, x-wedo-token");
|
|
|
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
|
+ if (req.method === "OPTIONS") { res.writeHead(204); return res.end(); }
|
|
|
const json = (code, obj) => { res.writeHead(code, { "content-type": "application/json; charset=utf-8" }); res.end(JSON.stringify(obj)); };
|
|
|
if (TOKEN && req.headers["x-wedo-token"] !== TOKEN) return json(401, { error: "unauthorized" });
|
|
|
const u = new URL(req.url, "http://x");
|