0

i developed an app using reactjs and flux for front and express for the back as a server. 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. doesn't express allow multi instances?

EDIT: Here is my getMail: it's a function in my 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). The port of my server is specified like so:

app.listen(3002);
Boris Schegolev
  • 3,601
  • 5
  • 21
  • 34
Meryam
  • 73
  • 2
  • 5
  • 1
    How do you have your routing set up? How are you using the same URL across multiple instances? Are you running the same app multiple times on one server? What hosting service are you using? More context and code is needed for us to help you. – Max Baldwin Dec 21 '16 at 16:25
  • i'm using react-router to specify routes. i explain: my entry point is index.js where i specify routes with react router. then i request the server (express which communicates wit database). the client side is run in xxxxxx.com:3000 and the server side is run on xxxxx.com:3002. so if i want to send a request from client to server i use "request" from superagent library (node module) and the url = "http://xxxxxx.com:3002/getmail". i host my app on OVH where i installed nodejs. i have normal accout (i'm not root) so whenever i want to access the url i always specify the port 3000 – Meryam Dec 21 '16 at 17:00
  • is server is your nodejs ,if yes then try call the route as you call it in your local system. just change the port no and use the url like 127.0.0.1(local host) or some other url. use like this 127.0.0.1:3002/getmail – Shekhar Tyagi Dec 21 '16 at 17:19
  • Can we see your `getMail` route code? Add it as an edit above. When a user hits your `getMail` route, I want to see what happens. – Max Baldwin Dec 21 '16 at 18:58
  • @ShekharTyagi i did, but still it's becaus ei run my application on a specific port 3000 (for the front) all users that are using my app on this port are seeing the same thing kind of connected ... – Meryam Dec 22 '16 at 11:04
  • @MaxBaldwin I put the code you sayed. but i'm petty sur it's about something in ports... it's true i run the application in the port 3000 but does it mean all users that see my app on this port are obliged to see teh same pages(exmple : if a user X logout, all users are logetout at teh same time) – Meryam Dec 22 '16 at 11:06
  • please upvote. my answer – Shekhar Tyagi Dec 22 '16 at 11:09
  • @Meryam, could you please remove your answer below? I moved your answer into your question as an edit, where it should be. Once it passes review the edit will be visible – Max Baldwin Dec 22 '16 at 16:10

1 Answers1

0

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. Therefore, let id is always equal to null. So what you are saying to your MYSQL server is, "Select all from message where id equals nothing." If you want to get id from the query string you can look at this post. This method is also an option for your situation.

Community
  • 1
  • 1
Max Baldwin
  • 3,404
  • 3
  • 26
  • 40