[英]Linked hosted application with nodejs and express
i developed an app using reactjs and flux for front and express for the back as a server. 我开发了一个使用reactjs和助焊剂作为前端的应用程序,并将后端表示为服务器。 everything worked fine.
一切正常。 but when i hosted the app tehre is a problem.
但是当我托管应用程序时,这是一个问题。 if more than one user is running the application via its url, the changes apply to all instances.
如果有多个用户通过其url运行该应用程序,则更改将应用于所有实例。 doesn't express allow multi instances?
不表示允许多实例?
EDIT: Here is my getMail: it's a function in my server.js 编辑:这是我的getMail:这是我的server.js中的一个函数
app.get('/api/getmail', function(req, res) {
try {
let id = req.param('id');
var options = { sql: 'SELECT * FROM message WHERE message_owner="' + id + '"', nestTables: true };
connection.query(options, function(err, result) {
if (err) throw err;
res.json(result);
});
} catch (error) {
res.json({ error: error });
}
});
When the user hits (in the front) getMails, a request is sent with an api i made (the api uses request from superagent/lib/client). 当用户点击(在最前面)getMails时,将发送一个带有我创建的api的请求(该api使用来自superagent / lib / client的请求)。 The port of my server is specified like so:
我的服务器的端口是这样指定的:
app.listen(3002);
So I can tell you that your issue is right here: 因此,我可以告诉您,您的问题就在这里:
let id = req.param('id');
The function req.param
has been deprecated in express . 函数
req.param
已在express中弃用 。 Therefore, let id
is always equal to null
. 因此,
let id
始终等于null
。 So what you are saying to your MYSQL
server is, "Select all from message where id equals nothing." 因此,您对
MYSQL
服务器说的是:“从ID不为空的消息中全选”。 If you want to get id
from the query string you can look at this post . 如果您想从查询字符串中获取
id
,可以查看这篇文章 。 This method is also an option for your situation. 您也可以使用此方法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.