@@ -32,6 +32,18 @@ var putHandler = require('./lib/handlers/put.js');
3232var deleteHandler = require ( './lib/handlers/delete.js' ) ;
3333var patchHandler = require ( './lib/handlers/patch.js' ) ;
3434
35+ // Setting up cors
36+ var corsSettings = cors ( {
37+ methods : [
38+ 'OPTIONS' , 'HEAD' , 'GET' ,
39+ 'PATCH' , 'POST' , 'PUT' , 'DELETE'
40+ ] ,
41+ exposedHeaders : 'User, Location, Link, Vary, Last-Modified, Content-Length' ,
42+ credentials : true ,
43+ maxAge : 1728000 ,
44+ origin : true
45+ } ) ;
46+
3547function ldnode ( argv ) {
3648 var ldp = new LDP ( argv ) ;
3749 var app = express ( ) ;
@@ -46,14 +58,14 @@ function ldnode (argv) {
4658 resave : false
4759 } ) ) ;
4860
49- // Setting up routes
50- app . use ( '/' , routes ( ) ) ;
51-
5261 // Adding proxy
53- if ( ldp . xssProxy ) {
54- proxy ( app , ldp . proxyFilter ) ;
62+ if ( ldp . proxy ) {
63+ proxy ( app , ldp . proxy ) ;
5564 }
5665
66+ // Setting up routes
67+ app . use ( '/' , routes ( ) ) ;
68+
5769 // Setup Express app
5870 if ( ldp . live ) {
5971 ws ( app ) ;
@@ -117,7 +129,7 @@ function createServer(argv) {
117129
118130function proxy ( app , path ) {
119131 debug . settings ( 'XSS Proxy listening to ' + path ) ;
120- app . get ( path , function ( req , res ) {
132+ app . get ( path , corsSettings , function ( req , res ) {
121133 debug . settings ( 'originalUrl: ' + req . originalUrl ) ;
122134 var uri = req . query . uri ;
123135 if ( ! uri ) {
@@ -138,16 +150,7 @@ function routes () {
138150 router . use ( header . linksHandler ) ;
139151
140152 // Setting CORS
141- router . use ( cors ( {
142- methods : [
143- 'OPTIONS' , 'HEAD' , 'GET' ,
144- 'PATCH' , 'POST' , 'PUT' , 'DELETE'
145- ] ,
146- exposedHeaders : 'User, Location, Link, Vary, Last-Modified, Content-Length' ,
147- credentials : true ,
148- maxAge : 1728000 ,
149- origin : true
150- } ) ) ;
153+ router . use ( corsSettings ) ;
151154
152155 router . use ( '/*' , function ( req , res , next ) {
153156 getRawBody ( req ,
0 commit comments