Skip to content

Commit 9b84000

Browse files
committed
fix: Fix CORS handling
1 parent 4fa1141 commit 9b84000

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const cors = require('./micro-cors.js')({
4848
allowHeaders,
4949
exposeHeaders,
5050
allowMethods,
51+
allowCredentials: false,
5152
origin
5253
})
5354
const allow = require('./allow-request.js')
@@ -86,6 +87,8 @@ async function service (req, res) {
8687
// Don't waste my precious bandwidth
8788
return send(res, 403, '')
8889
}
90+
91+
// Handle CORS preflight request
8992
if (req.method === 'OPTIONS') {
9093
return send(res, 200, '')
9194
}
@@ -120,4 +123,4 @@ async function service (req, res) {
120123
f.body.pipe(res)
121124
}
122125

123-
module.exports = cors(service)
126+
module.exports = cors(service)

micro-cors.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// MIT License
22
// https://github.com/possibilities/micro-cors
3+
// source: https://github.com/possibilities/micro-cors/pull/42
34
const DEFAULT_ALLOW_METHODS = [
45
'POST',
56
'GET',
@@ -26,11 +27,14 @@ const cors = (options = {}) => handler => (req, res, ...restArgs) => {
2627
maxAge = DEFAULT_MAX_AGE_SECONDS,
2728
allowMethods = DEFAULT_ALLOW_METHODS,
2829
allowHeaders = DEFAULT_ALLOW_HEADERS,
30+
allowCredentials = true,
2931
exposeHeaders = []
3032
} = options
3133

3234
res.setHeader('Access-Control-Allow-Origin', origin)
33-
res.setHeader('Access-Control-Allow-Credentials', 'true')
35+
if (allowCredentials) {
36+
res.setHeader('Access-Control-Allow-Credentials', 'true')
37+
}
3438
if (exposeHeaders.length) {
3539
res.setHeader('Access-Control-Expose-Headers', exposeHeaders.join(','))
3640
}

0 commit comments

Comments
 (0)