2017-05-22 12:03:45 -04:00
|
|
|
var restify = require('restify')
|
|
|
|
var cors = require('../src/index')
|
2014-05-07 22:16:17 -04:00
|
|
|
|
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
|
|
|
|
}
|
2014-05-07 22:16:17 -04:00
|
|
|
|
2017-05-22 12:03:45 -04:00
|
|
|
exports.noHeader = function (name) {
|
|
|
|
return function (res) {
|
2014-05-07 22:16:17 -04:00
|
|
|
if (res.headers.hasOwnProperty(name)) {
|
2017-05-22 12:03:45 -04:00
|
|
|
return 'Should not have header ' + name
|
2014-05-07 22:16:17 -04:00
|
|
|
}
|
2017-05-22 12:03:45 -04:00
|
|
|
}
|
|
|
|
}
|