Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
✨ disable CORS for public APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
fgruchala committed Apr 10, 2019
1 parent 114f960 commit 5e5475d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 34 deletions.
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ exports.makeBillingForPartner = functions.firestore.document('partners/{partnerI
exports.findAllActiveSpeakers = functions.https.onRequest(findAllActiveSpeakers);
exports.findAllSpeakersFromConferenceHall = functions.https.onCall(findAllSpeakersFromConferenceHall);

exports.findAllActiveTasks = functions.https.onRequest(findAllActiveTalks);
exports.findAllActiveTalks = functions.https.onRequest(findAllActiveTalks);

exports.findOneFromConferenceHall = functions.https.onCall(findOneFromConferenceHall);
14 changes: 3 additions & 11 deletions functions/src/partners/functions/find-all-active-partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ import * as cors from 'cors';
import editionsService from '../../editions/business/services/editions.service';
import partnersService from '../business/services/partners.service';

function checkOrigin(request, callback) {
const editionId = request.query.editionId;
const origin = request.header('Origin');

editionsService.findOne(editionId)
.then(edition => `https://${edition.url}` === origin ? callback(null, {origin: true}) : callback(null, {origin: false}))
.catch(err => {
console.error('checkOrigin', err);
callback(err, {origin: false});
});
function disableCors(request, callback) {
callback(null, true);
}

export default (request, response) => {
cors(checkOrigin)(request, response, () => {
cors(disableCors)(request, response, () => {
const editionId = request.query.editionId;
console.log('editionId', editionId);

Expand Down
14 changes: 3 additions & 11 deletions functions/src/speakers/functions/find-all-active-speakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import editionsService from '../../editions/business/services/editions.service';

import speakersService from '../business/services/speakers.service';

function checkOrigin(request, callback) {
const editionId = request.query.editionId;
const origin = request.header('Origin');

editionsService.findOne(editionId)
.then(edition => `https://${edition.url}` === origin ? callback(null, {origin: true}) : callback(null, {origin: false}))
.catch(err => {
console.error('checkOrigin', err);
callback(err, {origin: false});
});
function disableCors(request, callback) {
callback(null, true);
}

export default (request, response) => {
cors(checkOrigin)(request, response, () => {
cors(disableCors)(request, response, () => {
const editionId = request.query.editionId;
console.log('editionId', editionId);

Expand Down
14 changes: 3 additions & 11 deletions functions/src/talks/functions/find-all-active-talks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import speakersService from '../../speakers/business/services/speakers.service';

import talksService from '../business/services/talks.service';

function checkOrigin(request, callback) {
const editionId = request.query.editionId;
const origin = request.header('Origin');

editionsService.findOne(editionId)
.then(edition => `https://${edition.url}` === origin ? callback(null, {origin: true}) : callback(null, {origin: false}))
.catch(err => {
console.error('checkOrigin', err);
callback(err, {origin: false});
});
function disableCors(request, callback) {
callback(null, true);
}

export default (request, response) => {
cors(checkOrigin)(request, response, () => {
cors(disableCors)(request, response, () => {
const editionId = request.query.editionId;
console.log('editionId', editionId);

Expand Down

0 comments on commit 5e5475d

Please sign in to comment.