From c715b82edef3ad1236e113e8a706d9437a01be7c Mon Sep 17 00:00:00 2001 From: Ben Grant Date: Fri, 5 Mar 2021 14:27:54 +1100 Subject: [PATCH] CORS access through google endpoints --- crabfit-backend/index.js | 8 +++++--- crabfit-backend/swagger.yaml | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crabfit-backend/index.js b/crabfit-backend/index.js index 9100ca9..f79daea 100644 --- a/crabfit-backend/index.js +++ b/crabfit-backend/index.js @@ -16,19 +16,21 @@ const updatePerson = require('./routes/updatePerson'); const app = express(); const port = 8080; +const corsOptions = { + origin: process.env.NODE_ENV === 'production' ? 'https://crab.fit' : 'http://localhost:3000', +}; const datastore = new Datastore({ keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS, }); -app.use(cors({ - origin: process.env.NODE_ENV === 'production' ? 'https://crab.fit' : 'http://localhost:3000', -})); app.use(express.json()); app.use((req, res, next) => { req.datastore = datastore; next(); }); +app.options('*', cors(corsOptions)); +app.use(cors(corsOptions)); app.get('/', (req, res) => res.send(`Crabfit API v${package.version}`)); diff --git a/crabfit-backend/swagger.yaml b/crabfit-backend/swagger.yaml index 5dee8c1..750b507 100644 --- a/crabfit-backend/swagger.yaml +++ b/crabfit-backend/swagger.yaml @@ -4,6 +4,9 @@ info: description: "Compare and align schedules to find a time that works for everyone" version: "1.0.0" host: "api-dot-crabfit.appspot.com" +x-google-endpoints: +- name: "api-dot-crabfit.appspot.com" + allowCors: true schemes: - "https" produces: