Adds cors support to server

This commit is contained in:
Alicia Sykes
2023-09-03 14:11:15 +01:00
parent d41af54513
commit e23347a936
3 changed files with 2442 additions and 2425 deletions

View File

@ -2,6 +2,7 @@ const express = require('express');
const awsServerlessExpress = require('aws-serverless-express');
const fs = require('fs');
const path = require('path');
const cors = require('cors');
const historyApiFallback = require('connect-history-api-fallback');
require('dotenv').config();
@ -11,6 +12,11 @@ const API_DIR = '/api'; // Name of the dir containing the lambda functions
const dirPath = path.join(__dirname, API_DIR); // Path to the lambda functions dir
const guiPath = path.join(__dirname, 'build');
// Enable CORS
app.use(cors({
origin: process.env.API_CORS_ORIGIN || '*',
}));
// Execute the lambda function
const executeHandler = async (handler, req) => {
return new Promise((resolve, reject) => {