A form with POST method submitting a GET
<p>This is the strangest problem i ever had, this is the view (in jade):</p>

<pre><code>extends layout
block content
 h1 Edit chatroom!!
 form(method="POST")
      fieldset.form-group
          label(for="name") Name:
          input.form-control(name="name", type="text", placeholder="Enter a name" value="#{room.name}")
          small.text-muted Give your chatroom a meaningful name for people to refer to it.
      button.btn.btn-primary(type="submit") Save chatroom
      a.btn.btn-default(href="/admin/rooms") Cancel     
</code></pre>

<p>this is the form source from the page source code returned to the browser :</p>

<pre><code>&lt;form method="POST"&gt;
               &lt;fieldset class="form-group"&gt;&lt;label for="name"&gt;Name:&lt;/label&gt;&lt;input name="name" type="text" placeholder="Enter a name" value="independents" class="form-control"&gt;&lt;small class="text-muted"&gt;Give your chatroom a meaningful name for people to refer to it.&lt;/small&gt;&lt;/fieldset&gt;
               &lt;button type="submit" class="btn btn-primary"&gt;Save chatroom&lt;/button&gt;&lt;a href="/admin/rooms" class="btn btn-default"&gt;Cancel        &lt;/a&gt;
            &lt;/form&gt;
</code></pre>

<p>when i press the "Save chatroom" button i get this error message on the web page :</p>

<pre><code>Cannot GET /admin/rooms/edit/
</code></pre>

<p>this express router is supposed to handel the form submission </p>

<pre><code>router.route('/rooms/edit/:id')
.all(function(req, res, next) {
    var roomid = req.params.id;
    var room = _.find(rooms, r =&gt; r.id == roomid);
    if (!room) {
        res.sendStatus(404);
        return;
    }
    res.locals.room = room;
    next();
}).get(function(req, res) {
    res.render('edit');
}).post(function(req, res) {
    res.locals.room.name = req.body.name;
    //res.redirect(req.baseUrl + '/rooms'); or we can also
    res.redirect('./'); // but this is not good because if we had http://localhost:3000/admin/rooms/add/ it will take us to /add
});
</code></pre>

<p>the whole code for this small express app(two js files) exist in <a href="https://stackoverflow.com/questions/40839765/express-js-variable-stored-in-res-locals-isnt-defined-in-the-view">this previous question</a> i wrote.</p>