Есть приложение на node + express + mongoose
Проблема в том, что новый пользователь получает данные, которые запрашивались перед ним и т.д.
var express = require('express');
var http = require('http');
var path = require('path');
var mongoose = require("mongoose");
var async = require('async');
var fs = require('fs');
var crossroads = require('crossroads');
var base = __dirname;
var app = express();
var port = 4040;
http.createServer(app).listen(port);
app.engine("ejs", require("ejs-locals"));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser('your secret here'));
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
mongoose.connect("mongodb://localhost/youtube-v")
.then(() => console.log("Mongo has started..."))
.catch(e => console.log(e));
var myRes = ""
app.use(function(req, res, next) {
require("./models/person");
const Person = mongoose.model("persons");
var typeRoute = crossroads.addRoute('/id{id}');
typeRoute.matched.add(onTypeAccess);
function onTypeAccess(id) {
Person
.find({id: id})
.then(persons => {
myRes = JSON.stringify(persons, null, 2);
})
.catch();
};
crossroads.parse(req.url);
next();
});
app.use(function(req, res) {
console.log(myRes);
res.end(myRes);
})