mirror of
https://github.com/scratchfoundation/restify-cors-middleware.git
synced 2024-12-19 04:12:25 -05:00
25 lines
634 B
JavaScript
25 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;
|
||
|
}
|
||
|
};
|
||
|
};
|