Skip to content

Commit 3c0443f

Browse files
committed
Merge pull request #542 from CodeNow/fix-cors-domain-check-https
ignoring protocol for cors check
2 parents fffd645 + 970493b commit 3c0443f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/middlewares/cors.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
'use strict';
22
var cors = require('cors');
33
var envIs = require('101/env-is');
4+
var url = require('url');
45

56
module.exports = cors({
67
methods: 'GET,PUT,POST,PATCH,DELETE,DEL',
78
origin: function (origin, callback) {
9+
var originMatchesDomain = false;
10+
if (origin) {
11+
var originParsed = url.parse(origin);
12+
originMatchesDomain = (originParsed.host === process.env.DOMAIN);
13+
}
814
var allow = envIs('development', 'test', 'io', 'local', 'staging') ?
915
true :
10-
(origin === 'http://'+process.env.DOMAIN);
16+
(originMatchesDomain);
1117
callback(null, allow);
1218
},
1319
credentials: true

0 commit comments

Comments
 (0)