简体   繁体   中英

How to add server-side processing to a NodeJS React project

First part: given the source code of a pure NodeJS web site built on a framework (such as React), how do I tell which code runs server-side and which in the browser?

[This link https://reactjs.org/docs/create-a-new-react-app.html#create-react-app creates a sample of this kind.]

Then: how do I add server-side code (1) before (2) during (3) after in-browser processing?

Specific examples

  1. before: check a request server-side and deny if not authorised
  2. during: browser initiates lookup on server-held data, eg server local database/file system and displays the result
  3. after: server applies encryption to response using server private key.

Edit: this link https://www.fullstackreact.com/articles/using-create-react-app-with-a-server/ shows how to do (2) by running two servers and a proxy pass-through. It doesn't help with the other parts.

Please see the following tutorial . The discussion around the skeleton of the app explains the basics and then the explanation around app.js is very helpful.

In terms of the examples you provided, you can express authorization package on the server side to handle that. Once you have the server-side code set up you can handle the rest of the tasks. Hopefully, it helps :)

The answer is (a) it all runs in the browser and (b) you can't. The link given creates a single page app (SPA), and nothing gets sent to the server unless you make it so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM