CORS access through google endpoints

This commit is contained in:
Ben Grant 2021-03-05 14:27:54 +11:00
parent f9c216ad00
commit c715b82ede
2 changed files with 8 additions and 3 deletions

View file

@ -16,19 +16,21 @@ const updatePerson = require('./routes/updatePerson');
const app = express(); const app = express();
const port = 8080; const port = 8080;
const corsOptions = {
origin: process.env.NODE_ENV === 'production' ? 'https://crab.fit' : 'http://localhost:3000',
};
const datastore = new Datastore({ const datastore = new Datastore({
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS, 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(express.json());
app.use((req, res, next) => { app.use((req, res, next) => {
req.datastore = datastore; req.datastore = datastore;
next(); next();
}); });
app.options('*', cors(corsOptions));
app.use(cors(corsOptions));
app.get('/', (req, res) => res.send(`Crabfit API v${package.version}`)); app.get('/', (req, res) => res.send(`Crabfit API v${package.version}`));

View file

@ -4,6 +4,9 @@ info:
description: "Compare and align schedules to find a time that works for everyone" description: "Compare and align schedules to find a time that works for everyone"
version: "1.0.0" version: "1.0.0"
host: "api-dot-crabfit.appspot.com" host: "api-dot-crabfit.appspot.com"
x-google-endpoints:
- name: "api-dot-crabfit.appspot.com"
allowCors: true
schemes: schemes:
- "https" - "https"
produces: produces: