Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.io or REST api? #5

Closed
jaulz opened this issue Apr 8, 2015 · 9 comments
Closed

socket.io or REST api? #5

jaulz opened this issue Apr 8, 2015 · 9 comments
Labels

Comments

@jaulz
Copy link
Contributor

jaulz commented Apr 8, 2015

Any thoughts about how to integrate any of the both?

@iam4x
Copy link
Owner

iam4x commented Apr 8, 2015

For usage with socket.io, I would recommend reading: https://blog.rotenberg.io/million-user-webchat-with-full-stack-flux-react-redis-and-postgresql/

@iam4x iam4x added the question label Apr 8, 2015
@jaulz
Copy link
Contributor Author

jaulz commented Apr 8, 2015

Thanks for the link but I'm actually struggling where to exactly I should implement the API itself. Would you recommend to start a second project only for the API?

@iam4x
Copy link
Owner

iam4x commented Apr 12, 2015

With the new alt-resolver (#8) you can achieve easily the two possibilities:

fetch() {
  const promise = (resolve) => {
    if (process.env.BROWSER) {
      // fire xhr request
     users = xhr.fetch('http://example.com/api/users');
    }
    else {
      // retrieve users from database on the server
      const UserModel = require('user-model.js');
      users = UserModel.all();
    }
   return resolve();
  };
  altResolver.resolve(promise);
}

With UglifyJS well configured it will drop the condition as we build scripts for browser with process.env.BROWSER set to true.

@iam4x iam4x closed this as completed Apr 12, 2015
@aegyed91
Copy link
Contributor

aegyed91 commented Jun 3, 2015

So basically we have to make a separate node server as an api? Is there any way to simply ignore /api routes with react-router?

@iam4x
Copy link
Owner

iam4x commented Jun 3, 2015

@tsm91 you can: #45 (comment)

@aegyed91
Copy link
Contributor

aegyed91 commented Jun 3, 2015

aaaa the middleware stack, i was putting api routes after react-router ;)

@aegyed91
Copy link
Contributor

aegyed91 commented Jun 4, 2015

@iam4x i can't seem to get socket.io work while running webpack, i mean i constantly see the socketio pollings from browsersync and webpack probably.

any idea for that?

@iam4x
Copy link
Owner

iam4x commented Jun 4, 2015

I don't have any experience with socket.io sorry, but maybe would help: webpack/webpack-dev-server#76

@aegyed91
Copy link
Contributor

aegyed91 commented Jun 5, 2015

Yep i've tried that, the original problem is, webpack-dev-server's socket connection is on the default path.
Browsersync have done this right by the way, and on top of that it even gives configuration options.

As mentioned here io({path: '/custom/path'}) will make socket.io to connect to window.location.href + the path specified, in my case http://localhost:3002/custom/path which normally would solve the problem however its not, it still picks up webpack-dev-server's emitted events, i think i wont implement socket.io for now xd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants