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