mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 16:28:19 +00:00
fix: cors
This commit is contained in:
parent
5955879c07
commit
9048b28973
2 changed files with 9 additions and 13 deletions
|
|
@ -24,11 +24,12 @@
|
|||
"smee-client": "^2.0.3",
|
||||
"socket.io": "^4.8.1",
|
||||
"stegcloak": "^1.1.1",
|
||||
"ws": "^8.18.0"
|
||||
"ws": "^8.18.0",
|
||||
"cors": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.7.4",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,14 +28,9 @@ export const app = new App({
|
|||
path: "/send-private",
|
||||
method: ["POST"],
|
||||
async handler(req, res) {
|
||||
const headers = {
|
||||
"Access-Control-Allow-Origin":
|
||||
"*" /* @dev First, read about security */,
|
||||
"Access-Control-Allow-Methods": "OPTIONS, POST, GET",
|
||||
"Access-Control-Max-Age": 2592000, // 30 days
|
||||
/** add other headers as per requirement */
|
||||
};
|
||||
|
||||
await new Promise((resolve) => {
|
||||
require ("cors")(req,res,resolve)
|
||||
})
|
||||
const authHeader = req.headers["authorization"];
|
||||
if (authHeader !== process.env.AUTH) {
|
||||
res.writeHead(401).end();
|
||||
|
|
@ -49,7 +44,7 @@ export const app = new App({
|
|||
|
||||
//@ts-ignore
|
||||
if (!req.body || Object.keys(req.body) == 0) {
|
||||
res.writeHead(400, headers).end();
|
||||
res.writeHead(400).end();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
@ -60,11 +55,11 @@ export const app = new App({
|
|||
...req.body,
|
||||
})
|
||||
.then((d) => {
|
||||
res.writeHead(200, headers);
|
||||
res.writeHead(200);
|
||||
res.end(JSON.stringify(d));
|
||||
});
|
||||
} catch (e: any) {
|
||||
res.writeHead(500, headers);
|
||||
res.writeHead(500);
|
||||
res.end(e.stack);
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue