Skip to content

Commit 56a973f

Browse files
committed
fix: 🐛 Fixed invalid CORD handling in the node-api server
1 parent 65c192f commit 56a973f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/node-api/src/server.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ export class NodeApiServer {
397397
});
398398

399399
// Create a http server for handling of HTTP requests
400-
// TODO Implement origin configuration via .env
401400
this.server = createServer((req, res) => {
402-
res.setHeader('Access-Control-Allow-Origin', this.cors.join(', '));
403401
res.setHeader('Access-Control-Request-Method', 'GET');
404402
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
405403
res.setHeader(
@@ -408,6 +406,12 @@ export class NodeApiServer {
408406
);
409407
res.setHeader('Access-Control-Allow-Credentials', 'true');
410408

409+
const origin = req.headers.origin;
410+
411+
if (origin && this.cors.includes(origin)) {
412+
res.setHeader('Access-Control-Allow-Origin', origin);
413+
}
414+
411415
if (req.method === 'OPTIONS') {
412416
res.writeHead(200);
413417
res.end();

0 commit comments

Comments
 (0)