Emit allow headers for each request

post-data
Clément FRÉVILLE 1 year ago
parent 97a27d297a
commit 65dd2428b7

@ -14,16 +14,16 @@ const generateId = () => nanoid(32);
const clients: Record<string, http.ServerResponse> = {}; const clients: Record<string, http.ServerResponse> = {};
const CORS = {
'Access-Control-Allow-Methods': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': process.env.ALLOW_ORIGIN || '*',
};
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
if (req.method === 'OPTIONS') { if (req.method === 'OPTIONS') {
res.writeHead(200, { res.writeHead(200, CORS);
'Acess-Control-Allow-Methods': '*',
'Acess-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': process.env.ALLOW_ORIGIN || '*',
});
res.end(); res.end();
return; return;
} }
switch (req.url) { switch (req.url) {
@ -41,7 +41,7 @@ const server = http.createServer((req, res) => {
'Content-Type': 'text/event-stream', 'Content-Type': 'text/event-stream',
Connection: 'keep-alive', Connection: 'keep-alive',
'Cache-Control': 'no-cache', 'Cache-Control': 'no-cache',
'Access-Control-Allow-Origin': process.env.ALLOW_ORIGIN || '*', ...CORS,
}); });
sender.send(buffer).then(() => { sender.send(buffer).then(() => {
res.write('event: connected\n'); res.write('event: connected\n');

Loading…
Cancel
Save