Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helmet with connect (not express) #40

Closed
imrefazekas opened this issue Mar 30, 2014 · 2 comments
Closed

helmet with connect (not express) #40

imrefazekas opened this issue Mar 30, 2014 · 2 comments

Comments

@imrefazekas
Copy link

Hello,

I added helmet to my connect-based app and having an issue with it:

TypeError: Object #<ServerResponse> has no method 'header'
    at Object.handle (/.../helmet/lib/middleware/csp.js:26:17)
    at next (/.../node_modules/connect/lib/proto.js:193:15)

My configuration:

    var app = connect()
    .use( connect.static( pr.pathTo(global.codePath, 'dist/www') ) )
    .use( connect.query() )
    .use( connect.cookieParser() )
    .use( connect.session( { ... } ) )
    .use( connect.urlencoded() )
    .use( connect.json() )
    .use( connect.csrf() )
    .use( helmet.csp() );

Any help is much appreciated.

@hb9cwp
Copy link

hb9cwp commented Mar 30, 2014

For a quick fix, replace header( by setHeader( in /.../helmet/lib/middleware/csp.js. Or better, do an npm update to make sure that you have Helmet v0.1.3.
Hope this helps.

@imrefazekas
Copy link
Author

"make sure that you have Helmet v0.1.3." -helped not, and manually edit the helmet file would make any deploy not properly maintainable but by adding the following middleware would do the magic:

    .use( function(req, res, next){
        res.header = function(name, value){ this.setHeader(name, value); }.bind( res );
        next();
    } )

But I guess extend the prototype before creating connect app, would fit better to my case:

    http.ServerResponse.prototype.header = function(name, value){ this.setHeader(name, value); };

Hope, this helps to others.
Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants