mirror of
https://github.com/scratchfoundation/restify-cors-middleware.git
synced 2024-12-20 12:52:27 -05:00
24 lines
634 B
JavaScript
24 lines
634 B
JavaScript
var restify = require('restify');
|
|
var cors = require('../src/index');
|
|
|
|
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;
|
|
};
|
|
|
|
exports.noHeader = function(name) {
|
|
return function(res) {
|
|
if (res.headers.hasOwnProperty(name)) {
|
|
return 'Should not have header ' + name;
|
|
}
|
|
};
|
|
};
|