简体   繁体   English

将托管的应用程序与Node.js和Express链接

[英]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.

相关问题 NodeJS Express托管的GWT编译的应用程序未呈现CSS - NodeJS Express hosted GWT compiled application not rendering CSS 如何对我在Amazon Linux AMI上托管的nodejs express应用程序进行docker化? - how to dockerize my nodejs express application hosted on amazon linux ami? PayPal Express Checkout适用于Node.js应用程序 - Paypal express checkout for nodejs application 用于 API 的 NODEJS Express 应用程序生成器 - NODEJS Express application generator for API 如何为ElasticBeanStalk中托管的NodeJs应用程序指定端口? - How to specify port for NodeJs application hosted in ElasticBeanStalk? 无权访问Google Compute Engine上托管的NodeJS Express App - No Access to NodeJS Express App hosted on Google Compute Engine 如何在Openshift托管的Node.js上使用Express-Cloudant设置反向代理 - How to setup reverse proxy with express-cloudant on openshift hosted nodejs 如何使用 nodejs express 应用程序配置 eslint - How to configure eslint with nodejs express application 使用NodeJS / Express应用程序保护AJAX调用的安全 - Securing AJAX calls with a NodeJS/Express application Nginx Linux服务器上的Node.js Express应用程序 - Nodejs express application on nginx linux server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM