fix: Support multiple CORS origins via comma-separated BASE_URL
Closes #1344
This commit is contained in:
@@ -27,7 +27,8 @@ const envToBytes = (value) => bytes(value);
|
|||||||
|
|
||||||
const envToArray = (value) => (value ? value.split(',') : []);
|
const envToArray = (value) => (value ? value.split(',') : []);
|
||||||
|
|
||||||
const parsedBasedUrl = new URL(process.env.BASE_URL);
|
const baseUrl = envToArray(process.env.BASE_URL)[0];
|
||||||
|
const parsedBasedUrl = new URL(baseUrl);
|
||||||
|
|
||||||
module.exports.custom = {
|
module.exports.custom = {
|
||||||
/**
|
/**
|
||||||
@@ -38,7 +39,7 @@ module.exports.custom = {
|
|||||||
|
|
||||||
version,
|
version,
|
||||||
|
|
||||||
baseUrl: process.env.BASE_URL,
|
baseUrl,
|
||||||
baseUrlPath: parsedBasedUrl.pathname,
|
baseUrlPath: parsedBasedUrl.pathname,
|
||||||
baseUrlSecure: parsedBasedUrl.protocol === 'https:',
|
baseUrlSecure: parsedBasedUrl.protocol === 'https:',
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ module.exports.custom = {
|
|||||||
|
|
||||||
// TODO: move client base url to environment variable?
|
// TODO: move client base url to environment variable?
|
||||||
oidcRedirectUri: `${
|
oidcRedirectUri: `${
|
||||||
sails.config.environment === 'production' ? process.env.BASE_URL : 'http://localhost:3000'
|
sails.config.environment === 'production' ? baseUrl : 'http://localhost:3000'
|
||||||
}/oidc-callback`,
|
}/oidc-callback`,
|
||||||
|
|
||||||
smtpHost: process.env.SMTP_HOST,
|
smtpHost: process.env.SMTP_HOST,
|
||||||
|
|||||||
Vendored
+6
-6
@@ -23,7 +23,7 @@ const { URL } = require('url');
|
|||||||
|
|
||||||
const { customLogger } = require('../../utils/logger');
|
const { customLogger } = require('../../utils/logger');
|
||||||
|
|
||||||
const parsedBasedUrl = new URL(process.env.BASE_URL);
|
const origins = process.env.BASE_URL.split(',').map((baseUrl) => new URL(baseUrl).origin);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
@@ -133,10 +133,10 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
cors: {
|
cors: {
|
||||||
allRoutes: false,
|
allRoutes: true,
|
||||||
allowOrigins: '*',
|
allowOrigins: origins.slice(1),
|
||||||
allowRequestHeaders: 'content-type',
|
allowRequestHeaders: ['Authorization'],
|
||||||
allowCredentials: false,
|
allowCredentials: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onlyAllowOrigins: [parsedBasedUrl.origin],
|
onlyAllowOrigins: origins,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user