Steps towards removing the Restify dependency

This commit is contained in:
rprieto 2014-05-08 23:00:19 +10:00
parent a9f370e474
commit baa8543ff4
3 changed files with 33 additions and 12 deletions

19
src/actual.js Normal file
View 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
});
};

View file

@ -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)
};
};

View file

@ -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;