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);
8
  • 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. Commented Dec 21, 2016 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 = "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 Commented Dec 21, 2016 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 Commented Dec 21, 2016 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. Commented Dec 21, 2016 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 ... Commented Dec 22, 2016 at 11:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.