The server in angular-cli comes from the ember-cli project. To configure the server, create an .ember-cli file in the project root. Add your JSON config in there:
{
"proxy": "https://api.example.com"
}
重新启动服务器,它将代理那里的所有请求。
For example, I'm making relative requests in my code to /v1/foo/123, which is being picked up at https://api.example.com/v1/foo/123.
您还可以在启动服务器时使用一个标志:
ng serve --proxy https://api.example.com
You can use the 'router' option and some javascript code to rewrite the target URL dynamically.
为此,您需要在‘ start’脚本参数列表中指定一个 javascript 文件而不是 json 文件作为—— xy-conf 参数:
用密码
let url = "/api/clnsIt/dev/78";
这个网址会被翻译成 http://targetip:targetport/api/clnsit/dev/78。
You can also force rewrite by filling the pathRewrite. This is the link for details
Cmd/NPM 控制台会记录“ rewrite path from”/api/...”到“ http://targeturl:targetport/api/.."”,而浏览器控制台会记录“ http://loclahost/api"”;
> WARNING in
> D:\angular\Divya_Actian_Assignment\src\environments\environment.prod.ts
> is part of the TypeScript compilation but it's unused. Add only entry
> points to the 'files' or 'include' properties in your tsconfig.
> ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** : Compiled
> successfully. [HPM] GET
> /maps/api/geocode/json?sensor=false&address=chennai ->
> http://www.datasciencetoolkit.org