Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/apps/server/communication/uikit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import cors from 'cors';
import rateLimit from 'express-rate-limit';
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
Expand All @@ -14,6 +15,25 @@ const apiServer = express();

apiServer.disable('x-powered-by');

let corsEnabled = false;
let allowListOrigins = [];

settings.get('API_Enable_CORS', (_, value) => { corsEnabled = value; });
Comment thread
KevLehman marked this conversation as resolved.

settings.get('API_CORS_Origin', (_, value) => {
allowListOrigins = value ? value.trim().split(',').map((origin) => String(origin).trim().toLocaleLowerCase()) : [];
});

apiServer.use(cors({
origin: (origin, callback) => {
if (!origin || !corsEnabled || (allowListOrigins.includes('*') || allowListOrigins.includes(origin)) || origin === settings.get('Site_Url')) {
callback(null, true);
} else {
callback('Not allowed by CORS', false);
}
},
}));

WebApp.connectHandlers.use(apiServer);
Comment thread
KevLehman marked this conversation as resolved.

// eslint-disable-next-line new-cap
Expand Down