rest-query
Advanced tools
Comparing version
@@ -75,3 +75,4 @@ /* | ||
root: { value: app.createObjectNode( {} ) , enumerable: true } , | ||
collections: { value: {} , enumerable: true } | ||
collections: { value: {} , enumerable: true } , | ||
httpOptions: { value: {} , enumerable: true } | ||
} ) ; | ||
@@ -101,2 +102,12 @@ | ||
// Set up the behaviour for CORS, argument can be a string or a function( OriginHeader ) that return a CORS path. | ||
// Note that you don't have to give the full header, only the path. | ||
// E.g.: '*' -> 'Access-Control-Allow-Origin: "*"' | ||
restQuery.App.prototype.setAllowOrigin = function setAllowOrigin( rule ) | ||
{ | ||
this.httpOptions.allowOrigin = rule ; | ||
} ; | ||
restQuery.App.prototype.createCollectionNode = function createCollectionNode( name , descriptor , collectionNode ) | ||
@@ -211,3 +222,3 @@ { | ||
{ | ||
var performer , self = this ; | ||
var performer , headers , self = this ; | ||
@@ -218,2 +229,17 @@ restQuery.httpParser.parseRequest( httpRequest , function( error , message ) { | ||
headers = { 'Content-Type': 'text/html' } ; | ||
// CORS | ||
if ( self.httpOptions.allowOrigin ) | ||
{ | ||
if ( typeof self.httpOptions.allowOrigin === 'string' ) | ||
{ | ||
headers[ 'Access-Control-Allow-Origin' ] : '"' + self.httpOptions.allowOrigin + '"' ; | ||
} | ||
else if ( typeof self.httpOptions.allowOrigin === 'function' ) | ||
{ | ||
headers[ 'Access-Control-Allow-Origin' ] : '"' + self.httpOptions.allowOrigin( httpRequest.headers.origin ) + '"' ; | ||
} | ||
} | ||
//# debug : console.log( string.inspect( { style: 'color' } , message ) ) ; | ||
@@ -220,0 +246,0 @@ |
{ | ||
"name": "rest-query", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Perform REST queries directly on your database!", | ||
@@ -5,0 +5,0 @@ "main": "lib/restQuery.js", |
@@ -1166,2 +1166,9 @@ /* | ||
describe( "Misc" , function() { | ||
it( "Test CORS" ) ; | ||
} ) ; | ||
105442
0.9%2225
1.09%