2016-05-26 5 views
0

Ich benutze Helmmodul mit sails.js für Content Security Policy in app/config/http.jsmit sails.config in Middle

// app/config/http.js 
module.exports.http = { 
    order: [ 
     ... 
     'csp', 
     'router', 
     'www', 
     'favicon', 
     '404', 
     '500' 
    ], 
    ... 
    csp: require('helmet').csp({directives:{...}}), 
    ... 
} 

ich das Objekt in csp() will in meiner Config sein/local.js

// config/local.js 
module.exports = { 
    ... 
    csp: {directives:{...}}, 
    ... 
} 

Aber wenn ich require('helmet').csp(sails.config.csp) in app/config/http.js ich einen Fehler bekam:

ReferenceError: sails is not defined

Ich verstehe, warum es nicht definiert ist, aber ich weiß nicht, wie man sails.config.http abhängig von der Umgebung ändert

Antwort

1

Sie sollten nicht sails.config verweisen müssen. Ihre local.js sollte alle "Standardeinstellungen" überschreiben, die Sie in festgelegt haben.

Zum Beispiel:

// app/config/http.js 
module.exports.http = { 
    ... 
    csp: require('helmet').csp({directives:{...}}), // default settings 
    ... 
} 


// app/config/local.js 
module.exports = { 
    ... 
    // custom http settings for this environment 
    http: { 
     csp: require('helmet').csp({directives:{...}}) 
    } 
    ... 
} 
+0

ich habe es. Vielen Dank – Martial

Verwandte Themen