Front and rear separation, isomorphism, deployment problems?

problem description:

during this period of time, I am working on a project, and Web mainly uses the NodeJs Koa framework, React, React-router,redux, and so on.

the front end React-create-app generates the project and build generates static files.
NodeJs Koa provides Api.

now it is mainly the deployment problem:

see on the Internet that there are several ways:

  1. nginx

    my understanding is a nginx static server, which is mainly used for users to request to static resources, and
    node is deployed separately and is only used to provide APi.
    simply means that the front and rear ends are deployed separately.

  2. isomorphic

    Node returns directly to the page.
    in that case, there are two questions
    (1) how to tell whether the request is an api data interface or a page.
    (2) routing problem, whether React-router controls routing or node.

  3. returns the React packaged file as a static resource.

    when a user requests a home page, he or she returns the packaged index.html,
    and simply merges it into a project.

* * this will be a bit vague now.
by the way, the main question is how to release the front and rear separate projects,
the front end is clear.
it"s best to explain it in detail. Thank you. * *

split line--

add:

because my current project is a little simple. As long as you can run.
so I"m not going to use nginx

how can you simply integrate and use pm2 to make it run?

Front build into some static resource files.

how do I write it on the node side?

clipboard.png

clipboard.png

does not seem to work as a static resource, and all requests will return to this main page.

how should this block be written, or is there any example?


  1. Select 1 if you don't need SSR and 2 if you need it.
  2. uses the request path to distinguish between an api and a page.
  3. it depends on whether you need SPA or a multi-page application to decide whether it is a front-end route or a back-end route.

Thank you for the invitation!
I would like to talk about some personal views for everyone to discuss.
to discuss how to deploy, we are actually talking about the two possible conflicting requirements of being more efficient after deployment (more users supported and faster to respond to) and making it easier to change when development changes.
and these requirements are related to the actual needs and implementation of the application.

if you can ensure that everything is static and the front end implements routing (to request various resources), then it is certain that solution 1 is the most efficient. After all, nginx specializes in providing static resource services.

for the questions in your 2 solution, in fact, nodejs can deal with through default routing, that is, it will not be able to distinguish between api requests and document requests, at least a good and correct service framework certainly needs to do this. Of course, this will lead to the problem of document request efficiency (after all, nodejs service is not professional, it can only be said to be available, and it is also the reason why many large applications distinguish different resources and services through domain names, etc.).

The

3 scheme is not impossible, but the appropriateness of the scheme should be analyzed according to the actual situation.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48a45-59d1c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48a45-59d1c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?