Reputation: 13507
I've developed webapp (ReactJS, Flux, React-router; Server: NodeJS, Express) It does load initially only html (isomorphic way).
Now I need to hide some business logic from client side. For example, i have rating system. User should be able to vote only if he hasn't vote before. I guess, it should be like that: user pushes voting button. This button's handler function sends an object to the serverSide:
{
userName: login,
password: password,
votedObjectId: objectId
}
Server should check, if this user exists in database (by userName and password), and if this user has voted before for this object(by userName and votedObjectId). If everything is ok, server should add row to the Rating table (userName and votedObjectId)
I don't know how to implement it.
I suppose, I should create a js method in the server.js file, which will contain this logic. And client Side should trigger this method. How client side may send request to the server.js?
Upvotes: 1
Views: 870
Reputation: 5926
You have the right idea, you need to post your interaction to the server and have it process the business logic. Since your question is specifically how to send the request to the server to trigger this behavior, I'm guessing you've yet to implement any RESTful layer in your app.
Express.js is totally competent to do this, so I would look for a tutorial on implementing simple REST calls from client to server using the Express framework. You'll need to decide how you want to handle the AJAX calls from the browser, whether through some simple means like using JQuery or using a more full-fledged modeling layer, such as Backbone or the like.
It appears to me that the list of technologies you begin your post with is omitting this layer, and since React is the "View" in MVC, and React-Router is (kind-of) the "Controller", you still need the "Model" part - some way to represent your server API in the Javascript world.
Upvotes: 1