Skip to content

Commit

Permalink
feat: cors policy added
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatih Burak İlk committed Nov 11, 2024
1 parent d631a88 commit b00e710
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ const handleUrls = async (req, res, next) => {
};

const cors = async (req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', req.header('Origin'));
const { corsWhiteListDomains } = voltranConfig;
const { origin } = req.headers;
if (origin && corsWhiteListDomains?.map(domain => domain?.includes(origin))) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
} else {
res.setHeader('Access-Control-Allow-Origin', '*');
}
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, HEAD, OPTIONS');

if (req.method === 'OPTIONS') {
Expand Down

0 comments on commit b00e710

Please sign in to comment.