title: Express router.post not executing block, but found
body: <p>In my index.js file, each form action called executes properly:</p>
  
  <p>routes/index.js</p>
  
  <pre><code>var express = require('express');
  var async = require('async');
  var common = require('./common.js');
  var log = require('./log.js');
  var router = express.Router();
  
  router.post('/premise', function...
  
  router.post('/follow', function...
  </code></pre>
  
  <p>views/index.jade</p>
  
  <pre><code>extends layout
  
  block js
    script(src='/javascripts/countdown.js')
    script(src='/javascripts/table_filter.js')
  
  block content
    if username...
  
           ...div.followers.table_wrapper
                h3.table_header.center Following
                #followers_tbl.center
                  h4.center You are not following anyone...
                  form(action="follow" method="post")
                    input(type="text" name="follow_username" id="follow_username" placeholder="Add username here...")
                    button(class="btn btn-primary btn-sml" type="submit" style="margin-bottom: 15px") Follow A User
            div#add_premise.textarea_wrapper
              form(action="premise" name="premise" method="post")
                textarea(name="premise" id="premise" placeholder="Enter your..." required)
                p.countdown.black
                button(class="btn btn-success" type="submit") Add Premise
  </code></pre>
  
  <p>But when I call from another page /signup it doesn't work. (See below EDIT file details).</p>
  
  <p>The call returns a 302, so it is found, but the function doesn't execute. But when I remove <code>action='signup/signup/'</code> from the form in the view, then change the <code>router.post('/signup', function...</code> to <code>router.post('/', function...</code>, the function executes, after also returning a 302 in my log.</p>
  
  <p>Can anyone help me? Thanks so much!</p>
  
  <p>EDIT: (Adding app.js and more of routes/signup.js)</p>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var session = require('express-session');
  var fileStore = require('session-file-store')(session);
  
  var index = require('./routes/index.js');
  var signup = require('./routes/signup.js');
  var login = require('./routes/login.js');
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  var session_options = {
    name: 'server-session-cookie-id',
    secret: 'secret',
    saveUninitialized: true,
    resave: true,
    store: new fileStore(),
    cookie: {
      maxAge: 1000 * 60 * 60 * 24 * 365 // 1 year
    }
  };
  
  // uncomment after placing your favicon in /public
  app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(session( session_options ));
  
  app.use( function( req, res, next ) {
    try {
      if ( ( req.session &amp;&amp; req.session.username ) ||
        req.originalUrl == "/login" ||
        req.originalUrl == "/signup" {
        next();
      }
      else {
        res.redirect('/login');
      }
    }
    catch( err ) {
      common.send_500( req, res, err );
    }
  });
  
  app.use('/', index);
  app.use('/signup', signup);
  app.use('/login', login);
  
  app.get('/logout', function(req, res, next) {
    try {
      req.session.destroy();
      res.clearCookie(session_options.name);
      res.redirect('/');
    }
    catch( err ) {
      common.send_500( req, res, err );
    }
  });
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
  });
  
  // error handlers
  
  // development error handler
  // will print stacktrace
  if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
        message: err.message,
        error: err
      });
    });
  }
  
  // production error handler
  // no stacktraces leaked to user
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: {}
    });
  });
  
  module.exports = app;
  </code></pre>
  
  <p>routes/signup.js</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var encrypt = require('./encrypt.js');
  var common = require('./common.js');
  var log = require('./log.js');
  
  /* GET signup page. */
  router.get('/', function(req, res, next) {
    try {
      var signup_error = req.session.signup_error;
      req.session.signup_error = null;
      res.render('signup', { title: 'Signup', signup_error: signup_error });
    }
    catch( err ) {
      common.send_500( req, res, err );
    }
  });
  
  router.post('/normal', function(req, res, next) {...});
  
  router.post('/submit', function(req, res, next) {...});
  
  module.exports = router;
  </code></pre>
  
  <p>views/signup.jade</p>
  
  <pre><code>extends layout
  
  block js
    script(src='/javascripts/dob_validate.js')
  
  block content     
                div#signup_form
                    form(action="/signup/normal" name="signup" method="post")
                      input(type="email" name="email" id="email" placeholder="Email" required autofocus)
                      input(type="text" name="username" id="username" placeholder="Username" required)
                      input(type="password" name="password1" id="password1" placeholder="Password" required)
                      input(type="password" name="password2" id="password2" placeholder="Confirm Password" required)
                      p#dob
                        | Birthdate
                        input(type="date" name="birthdate" id="birthdate" style="margin-left=20px;" required).pull-right
                      label
                        input(style="margin-right: 5px;" type="checkbox" name="checkbox" required).pull-left
                        | Check here to indicate that you have read, understand and agree to the
                        a(href="/terms")  Terms of Use,
                        a(href="/privacy")  Privacy Policy
                        |  and
                        a(href="/cookies")  Cookie Policy
                        | .
                      div#signup_btns
                        button(class="btn btn-primary" type="submit") Sign Up
                        a(href='/login') Login
  </code></pre>
  
  <p>/signup/normal/ handler:</p>
  
  <pre><code>router.post('/normal', function(req, res, next) {
    try {
      var email = req.body.email;
      var username = req.body.username.toUpperCase();
      var password1 = req.body.password1;
      var password2 = req.body.password2;
      var birthdate = req.body.birthdate;
  
      birthdate = birthdate.substring(5,7) + '/' +
        birthdate.substring(8,10) + '/' +
        birthdate.substring(0,4);
  
      if (password1 === password2) {
        var body = JSON.stringify({
          "username"      : username,
          "password_hash" : encrypt.hash(password1),
          "credits"       : 100,
          "email_address" : email,
          "birthdate"     : birthdate
        });
  
        var path = "/accounts/add/";
  
        common.post( path, body, function( data ) {
          try {
            if ( data &amp;&amp; !data.error ) {
              console.log(JSON.parse(data.resp));
              res.redirect('/login');
            }
            else {
              req.session.signup_error = data.resp;
              req.session.save( function(err) {
                res.redirect('/signup');
              });
            }
          }
          catch( err ) {
            common.send_500( req, res, err );
          }
        });
      }
      else {
        req.session.signup_error = "Passwords do not match";
        req.session.save( function(err) {
          res.redirect('/signup');
        });
      }
    }
    catch( err ) {
      common.send_500( req, res, err );
    }
  });
  </code></pre>