pdupavillon / express-recaptcha

Implementation of google recaptcha v2 & V3 solutions for express.js
MIT License
128 stars 22 forks source link

Cannot set headers after they are sent to the client #37

Closed 1Map closed 4 years ago

1Map commented 4 years ago

I get following in my log:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (/mycode/node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/mycode/node_modules/express/lib/response.js:170:12)
    at done (/mycode/node_modules/express/lib/response.js:1008:10)
    at Object.exports.renderFile (/mycode/node_modules/pug/lib/index.js:421:12)
    at View.exports.__express [as engine] (/mycode/node_modules/pug/lib/index.js:464:11)
    at View.render (/mycode/node_modules/express/lib/view.js:135:8)
    at tryRender (/mycode/node_modules/express/lib/application.js:640:10)
    at Function.render (/mycode/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/mycode/node_modules/express/lib/response.js:1012:7)
    at app.get (/mycode/routes/index.js:9:7)
    at Layer.handle [as handle_request] (/mycode/node_modules/express/lib/router/layer.js:95:5)
    at next (/mycode/node_modules/express/lib/router/route.js:137:13)
    at render (/mycode/node_modules/express-recaptcha/dist/v3.js:32:21)
    at Layer.handle [as handle_request] (/mycode/node_modules/express/lib/router/layer.js:95:5)
    at next (/mycode/node_modules/express/lib/router/route.js:137:13)

And the code at:

at app.get (/mycode/routes/index.js:9:7)

is as follow:

    /* GET home page. */
    app.get('/', recaptcha.middleware.render, (req, res, next) => {
        res.render('index', {
            title: 'My Title',
            lastPath: '/',
            captcha: res.recaptcha
        })
    })
pdupavillon commented 4 years ago

Hey @1Map, Sorry, I can't help with that kind of information, If you could send me a repo to reproduce that issue, that could help a lot! Also please check the example folder, where there is no such error: https://raw.githubusercontent.com/pdupavillon/express-recaptcha/master/example/server.js

Thank you