CORS access through google endpoints
This commit is contained in:
parent
f9c216ad00
commit
c715b82ede
|
|
@ -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}`));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue