mirror of
https://github.com/scratchfoundation/restify-cors-middleware.git
synced 2024-12-18 11:52:26 -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 restify = require('restify');
|
||||
var preflight = require('./preflight');
|
||||
var actual = require('./actual');
|
||||
|
||||
module.exports = function(options) {
|
||||
|
||||
|
@ -9,17 +9,8 @@ module.exports = function(options) {
|
|||
if (! util.isArray(options.exposeHeaders)) options.exposeHeaders = [];
|
||||
|
||||
return {
|
||||
|
||||
actual: restify.CORS({
|
||||
origins: options.origins,
|
||||
headers: options.exposeHeaders
|
||||
}),
|
||||
|
||||
preflight: preflight.handler({
|
||||
origins: options.origins,
|
||||
allowHeaders: options.allowHeaders
|
||||
})
|
||||
|
||||
actual: actual.handler(options),
|
||||
preflight: preflight.handler(options)
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
var restify = require('restify');
|
||||
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 HTTP_NO_CONTENT = 204;
|
||||
|
||||
|
|
Loading…
Reference in a new issue