From the Java world where a servlet-based context context based on the WAR file name is set, I am trying to understand the best methods for determining the context path in Node.js.
The Node application in question does not specify the context path defined in the code. The Express code assumes that the story request, for example, has a URL with the path / story / 1. Thus, the JavaScript user interface code will make the request http: // host: port / story / 1 . Similarly, so that the user can connect to the main page of the application, they will go to http: // host: port / .
I would like to change the URL that the user sees http: // host: port / myapp . The question is how to sequentially define "myapp" as an application context. The options I'm considering are:
- Defining context in Express.js code.
- Definition of context in the Nginx proxy server.
How can I make sure the user always sees "myapp" in the URL? Do I also need to reassign all internal requests (those made using the user interface code) to also have a "/ myapp" context?
Using Nginx seems cleaner since it does not require code changes. But can this goal be achieved only with the Nginx configuration, and if so, how?
Since this is a common problem, there must be a well-defined pattern to solve it.
source share