From a2dc3ca2dcc9ac33558e2503d24654a895f113f7 Mon Sep 17 00:00:00 2001 From: Irenej Bozovicar Date: Mon, 8 Jan 2024 13:45:11 +0100 Subject: [PATCH] Protect functions through CORS --- functions/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/functions/index.js b/functions/index.js index 2513af5..9558ba6 100644 --- a/functions/index.js +++ b/functions/index.js @@ -5,8 +5,15 @@ const routes = require('./routes'); // Adjust the path const app = express(); -// Enable CORS -app.use(cors()); +const isProduction = process.env.NODE_ENV === 'production'; + +// Enable CORS with dynamic origin configuration +const corsOptions = { + origin: isProduction ? 'https://wordclips.org' : true, // Set to true for development +}; + +// Use CORS middleware with dynamic options +app.use(cors(corsOptions)); app.use('/', routes); // Use the routes