mirror of
https://github.com/scratchfoundation/restify-cors-middleware.git
synced 2024-12-19 12:22:23 -05:00
Steps towards removing the Restify dependency
This commit is contained in:
parent
a9f370e474
commit
baa8543ff4
3 changed files with 33 additions and 12 deletions
19
src/actual.js
Normal file
19
src/actual.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
var restify = require('restify');
|
||||||
|
|
||||||
|
//
|
||||||
|
// For now, delegate to restify.CORS
|
||||||
|
//
|
||||||
|
// Although there's a few things we could fix
|
||||||
|
// around Access-Control-Expose-Headers
|
||||||
|
//
|
||||||
|
// It would also break the cyclic dependency with Restify :)
|
||||||
|
//
|
||||||
|
|
||||||
|
exports.handler = function(options) {
|
||||||
|
|
||||||
|
return restify.CORS({
|
||||||
|
origins: options.origins,
|
||||||
|
headers: options.exposeHeaders
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
15
src/index.js
15
src/index.js
|
@ -1,6 +1,6 @@
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var restify = require('restify');
|
|
||||||
var preflight = require('./preflight');
|
var preflight = require('./preflight');
|
||||||
|
var actual = require('./actual');
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
|
|
||||||
|
@ -9,17 +9,8 @@ module.exports = function(options) {
|
||||||
if (! util.isArray(options.exposeHeaders)) options.exposeHeaders = [];
|
if (! util.isArray(options.exposeHeaders)) options.exposeHeaders = [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
actual: actual.handler(options),
|
||||||
actual: restify.CORS({
|
preflight: preflight.handler(options)
|
||||||
origins: options.origins,
|
|
||||||
headers: options.exposeHeaders
|
|
||||||
}),
|
|
||||||
|
|
||||||
preflight: preflight.handler({
|
|
||||||
origins: options.origins,
|
|
||||||
allowHeaders: options.allowHeaders
|
|
||||||
})
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
var restify = require('restify');
|
var restify = require('restify');
|
||||||
var origin = require('./origin');
|
var origin = require('./origin');
|
||||||
|
|
||||||
|
//
|
||||||
|
// For now we use the "default headers" from restify.CORS
|
||||||
|
// Maybe this should just be a global setting on this module
|
||||||
|
// (ie. list of extra Access-Control-Expose-Headers, regardless of what the middleware config says)
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO:
|
||||||
|
// Handle the spec better around "simple methods" and "simple headers".
|
||||||
|
//
|
||||||
|
|
||||||
var DEFAULT_ALLOW_HEADERS = restify.CORS.ALLOW_HEADERS;
|
var DEFAULT_ALLOW_HEADERS = restify.CORS.ALLOW_HEADERS;
|
||||||
var HTTP_NO_CONTENT = 204;
|
var HTTP_NO_CONTENT = 204;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue