Skip to content
Open

V1 #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@
"type": "git"
},
"author": "Mike Bannister <mikebannister@gmail.com>",
"main": "lib/index.js",
"main": "src/index.js",
"files": [
"lib/index.js"
"src/index.js"
],
"license": "MIT",
"scripts": {
"build": "rimraf lib && babel src --out-dir lib",
"test": "ava --verbose src/test.js",
"dev": "ava --verbose --watch src/test.js",
"prepublish": "yarn build",
"lint": "standard",
"pretest": "yarn lint"
},
"devDependencies": {
"async-to-gen": "^1.3.2",
"ava": "^0.19.0",
"babel-cli": "^6.24.0",
"babel-polyfill": "^6.23.0",
"babel-preset-latest": "^6.24.0",
"babel-preset-stage-0": "^6.22.0",
"babel-register": "^6.24.0",
"@ava/babel": "^1.0.1",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"ava": "^3.8.2",
"micro": "^7.3.0",
"request": "^2.85.0",
"request-promise": "^4.2.0",
Expand All @@ -40,15 +37,17 @@
},
"ava": {
"failFast": true,
"require": [
"babel-register"
],
"babel": "inherit"
"babel": true
},
"babel": {
"presets": [
"latest",
"stage-0"
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-transform-runtime"
]
},
"dependencies": {
"@babel/runtime": "^7.9.6"
}
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const cors = (options = {}) => handler => async (req, res, ...restArgs) => {
setVaryHeader(res, origin)
res.end()
} else {
const handlerResult = await handler(req, res, ...restArgs)
setVaryHeader(res, origin)
const handlerResult = await handler(req, res, ...restArgs)
return handlerResult
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import microCors from './index'
import micro from 'micro'
import request from 'request-promise'

import 'babel-polyfill'

const testRequestOptions = {
json: true,
// Otherwise request-promise just gives the body
Expand Down Expand Up @@ -365,11 +363,11 @@ test('includes Vary header for dynamic origins', async t => {
}
})

test('appends Vary header if there is already a value', async t => {
test('append Vary header', async t => {
const cors = microCors({ origin: ['foo.com', 'bar.com'] })
const router = micro(
cors((req, res) => {
res.setHeader('Vary', 'Foo')
res.setHeader('Vary', res.getHeader('Vary') + ',Foo')
return {}
})
)
Expand All @@ -385,7 +383,7 @@ test('appends Vary header if there is already a value', async t => {
if (method === 'OPTIONS') {
t.is(response.headers['vary'], 'Origin')
} else {
t.is(response.headers['vary'], 'Foo,Origin')
t.is(response.headers['vary'], 'Origin,Foo')
}
}
})
Loading