Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Allow cross-origin requests from antifraudcentre (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosset authored Feb 7, 2020
1 parent 9bd80c1 commit c690a97
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions f2/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const MongoClient = require('mongodb').MongoClient

const dbName = process.env.COSMOSDB_NAME
const dbKey = process.env.COSMOSDB_KEY
const allowedOrigins = [
'http://dev.antifraudcentre-centreantifraude.ca',
'http://pre.antifraudcentre-centreantifraude.ca',
'http://antifraudcentre-centreantifraude.ca',
'http://centreantifraude-antifraudcentre.ca',
'http://antifraudcentre.ca',
'http://centreantifraude.ca',
]

let cosmosDbConfigured = dbName && dbKey
if (!cosmosDbConfigured) {
Expand Down Expand Up @@ -99,6 +107,21 @@ let count = 0
app
.use(express.static(path.join(__dirname, 'build')))
.use(bodyParser.json())
.use(function(req, res, next) {
var origin = req.headers.origin
// Can only set one value of Access-Control-Allow-Origin, so we need some code to set it dynamically
if (
origin !== undefined &&
allowedOrigins.indexOf(origin.toLowerCase()) > -1
) {
res.header('Access-Control-Allow-Origin', origin)
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept',
)
}
next()
})

.get('/ping', function(_req, res) {
return res.send('pong')
Expand Down

0 comments on commit c690a97

Please sign in to comment.