Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
module.exports = function(app) {
app.post('/createStation', function(request, response){
response.redirect('/'); //This doesn't work, why and how to make this work
/*var stationDao = require('./server/stationDao.js');
stationDao.stationDao.createStation(request.body, function(status){
if(status.status == 'successful'){
response.redirect('/'); //This is what actually I wanted to do
Tried using next() as well,
app.post('/createStation', [function(request, response, next){
var stationDao = require('./server/stationDao.js');
stationDao.stationDao.createStation(request.body, function(status){
if(status.status == 'successful'){
next();
}, function abc(request, response){
console.log('I can see this');
response.redirect('/'); //This doesn't work still
–
–
–
On the subject: http://expressjs.com/guide/routing.html#route-handlers
EDIT based on comment:
I've just wrote a really basic server to test what I wrote:
var express = require('express');
var app = express();
app.post('/a', [function(req, res, next) {
next();
}, function(req, res) {
res.send('Hello World!');
var server = app.listen(3000, function () { console.log('listening'); });
This works for me, I would encourage you to run that and then curl -X POST http://localhost:3000/a
, in my case I correctly got "Hello World!".
If this also works for you try to isolate your problem a bit more by removing some bits and pieces.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.