node.js - Express finalhandler cannot 404 after headers sent -


i have express app , have added new route:

this route:

var router = require('express').router();  router.post('/',function (req, res, next) {   res.send("ok"); });  module.exports = router; 

now on every request make post route im getting @ express log:

finalhandler cannot 404 after headers sent

when making calls db finalhandler send 404 every requst,

so im guessing there kind of race functions , finalhandler

anyone have anyidea?

update:

this index.js

var express = require('express'); var app = express(); var bodyparser = require('body-parser'); var expressvalidator = require('express-validator');  var _ = require('underscore'); var stringutils = require("underscore.string");  var mongoose = require('mongoose'); mongoose.connect(config.mongourl); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:'));  app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: true })); app.use(expressvalidator());  var middleware = require('./middleware/authentication-middleware'); app.use(middleware.allowcrossdomains); app.all('*', loginmiddlewareskip);  var skipauthpaths = ['/auth/fb', '/auth/login', '/auth/signup',     '/auth/forgot', '/auth/reset']; function loginmiddlewareskip(req, res, next) {     if (stringutils.startswith(req.path, "/auth") || req.path ==     '/status'){          return next();     }      middleware.ensureauthenticated(req,res,next);     next(); }  app.use('/passport', require('./routes/passport')); app.use('/auth', require('./routes/authenticate'));   app.listen(3000, function() {     console.log('express server listening on port ' + 3000); }); 

the file above routes/passport, , auth file working fine

ok problem 1 of middle wares:

in loginmiddlewareskip function calling middleware.ensureauthenticated(req,res,next) if path need authentication, inside function calling next() if authentication successfull , can see calling next() again after calling ensureauthenticated function.

removing next() loginmiddlewareskip solved problem


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -