This overheard me for a while, and it seems that every week I come up with different pros and cons.
The bottom line is that a good SPA is divided into two different parts. Interface and interface. The interface should only be associated with static files (javascript, css, html, etc.), while the internal server serves the actual data and is dynamic. However, one part that always seems dynamic to me with the interface is the reverse URL .
What I mean is that I usually submit my application, say http://server:123/ and my API is from http://other:456/api . Often, the other and server same, and the ports are changing, but this does not always happen as you scale.
So my question is: What are the best methods for providing configuration data in an Angular 2 application?
Here is what I was thinking:
proxies
Most web servers, even mostly static content-oriented ones, offer some proxy configuration (nginx, angular-cli serve, etc.). The problem with the proxy server is that the request performs a double transition. First, it must be sent to a static server, and then this server must be deployed and execute a real request. I am not a fan of this architecture, although I have used it in the past in other applications.
configuration file
This is currently my favorite. I pretty much serve a static file (say /config.json ) from my static content server that contains one or more URLs or other non-sensitive information. I like this approach because it allows you to use a proxy server or not. This is for you. In most cases, itβs quite simple to configure the web server to return a static file based on the URL (say /config ).
code configuration
This is my least favorite. In this approach, the configuration is written directly to the code file (for example, config.ts ) and must be changed for each environment. I believe that code and configuration are two different tasks, and in most of the companies I worked with, they are handled by two different teams. It would be foolish to recompile your code and redeploy only to change your internal URL.
angular angular-cli
Eric Liprandi
source share