mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 05:33:26 +00:00
Handle invalid CORS origin
This commit is contained in:
13
src/index.ts
13
src/index.ts
@@ -30,11 +30,16 @@ app.use('*', (context, next) => {
|
||||
|
||||
return cors({
|
||||
origin: (origin) => {
|
||||
const hostname = new URL(origin).hostname;
|
||||
if (allowedCorsHosts.includes(hostname)) {
|
||||
return origin;
|
||||
try {
|
||||
const hostname = new URL(origin).hostname;
|
||||
if (allowedCorsHosts.includes(hostname)) {
|
||||
return origin;
|
||||
}
|
||||
return '';
|
||||
} catch (_) {
|
||||
// If the Origin URL is not valid, return empty allowed origin
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
})(context, next);
|
||||
});
|
||||
|
Reference in New Issue
Block a user