restify-cors-middleware/test/test.js

25 lines
621 B
JavaScript
Raw Normal View History

2017-05-22 12:03:45 -04:00
var restify = require('restify')
var cors = require('../src/index')
2017-05-22 12:03:45 -04:00
exports.corsServer = function (corsConfig) {
var middleware = cors(corsConfig)
var server = restify.createServer()
server.pre(middleware.preflight)
server.use(middleware.actual)
server.get('/test', function (req, res, next) {
res.header('Custom-Response-Header', '123456')
res.header('Max-Age', 5 * 60 * 1000)
res.send(200, 'ok')
next()
})
return server
}
2017-05-22 12:03:45 -04:00
exports.noHeader = function (name) {
return function (res) {
if (res.headers.hasOwnProperty(name)) {
2017-05-22 12:03:45 -04:00
return 'Should not have header ' + name
}
2017-05-22 12:03:45 -04:00
}
}