I have a route in my express app, which is supposed to do the following:
- Get some data from outside (OK)
- Show a HTML page with socket.io listening for messages (OK)
- Perform some calculations, which take a long time
- Send a message trough socket.io after each one one completed (OK)
- When all calculations are completed, show a result page (problem)
So, a simplified version of my code is:
module.exports = function(io) { // This is so I can use socket.io inside the route
var express = require('express');
var router = express.Router();
[... and other required]
router.post('/', function(req, res, next) {
res.render('loading'); // This renders the template which holds accepts and renders socket.io messages
pefromCalculaton();
sendSocketIOMessage();
session.data = resultData; // I get the result of all calculations and put that in the session. It's a quick fix, don't judge, I've got no presistancy in my project as for now...
res.redirect('results'); // And here I'd like to go to the other route, which will display the data, getting it from the session.
});
return router;
}
Since this doesn't work, I am probably trying to do something really stupid here. But what I actually want to do is:
- Perform calculations
- While performing the calculations, update progress using sockets
- When calculation is done, render a template, showing all the results.