解释proxy.config.json功能角度5 [英] explain proxy.config.json features angular 5

查看:653
本文介绍了解释proxy.config.json功能角度5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"/api/*": {
  "target": "https://localhost:8000/api",
  "secure": false,
  "logLevel": "debug",
  "pathRewrite": {
    "^/api": ""
  },
  "changeOrigin": true
}

请在此代码段中提供每个功能的详细用法

Please provide detailed use of each feature in this code snippet

感谢您的帮助

推荐答案

   "/api/*": {
      "target": "https://localhost:8000",
      "secure": false,
      "logLevel": "debug",
      "pathRewrite": {
        "^/api": ""
      },
      "changeOrigin": true
    }

  1. "api/*":
    您的应用程序中对/api/的所有请求都将转发到 target": "https://localhost:8000/api
  2. "secure": false,:
    在HTTPS上运行的后端服务器,带有 默认情况下,无效证书将不被接受.如果你想, 您需要设置secure: false.

  1. "api/*":
    All requests made to /api/ from within your application will be forwarded to target": "https://localhost:8000/api
  2. "secure": false,:
    A backend server running on HTTPS with an invalid certificate will not be accepted by default. If you want to, you need to set secure: false.

"logLevel": "debug"
帮助调试您的代理是否 工作正常,您还可以将logLevel选项添加为 如下:logLevel的可能选项包括debuginfowarnerrorsilent(默认为info).

"logLevel": "debug"
To help debug whether or not your proxy is working properly, you can also add the logLevel option as follows: Possible options for logLevel include debug, info, warn, error, and silent (default is info).

"pathRewrite": { "^/api": "" }, pathRewrite设置指出,如果路径匹配^/api(即,它以/api开头),则用空字符串重写该部分(即,将其从路径中删除),因此所有对https://localhost:8000/api的请求都将转到

"pathRewrite": { "^/api": "" }, pathRewrite setting says that if the path matches ^/api (i.e. if it starts with /api) then rewrite that portion with the empty string (i.e. remove it from the path), so all the request to https://localhost:8000/api will go to https://localhost:8000

"changeOrigin": true:如果您需要访问不在本地主机上的后端,或者在后端上使用某些虚拟代理(例如使用Apache2配置的虚拟代理)时,请将其设置为true.

"changeOrigin": true: If you need to access a backend that is not on localhost or when you’re using some virtual proxies (such as configured with Apache2) on your backend set it to true.

此软件包中提供的

proxy options 来自底层 node-http-proxy

proxy options provided in this package is from underlying node-http-proxy

代理支持可以帮助您摆脱某些 CORS 在开发阶段出现异常,但客户端应用程序无法处理这些异常.必须将服务器配置为接受应用程序的请求.
I want to add CORS support to my server

Proxying Support might help you to get rid off some CORS exceptions during the development stage but There isn't much the client application can do about these exceptions The server must be configured to accept the application's requests.
I want to add CORS support to my server

注意:proxy配置用于通过ng serve运行开发服务器时代理调用.运行ng build后,您将负责Web服务器及其配置.

NOTE: The proxy configuration is intended to proxy calls when running the dev server via ng serve. After you run ng build you are responsible for the web server and its configurations.

这篇关于解释proxy.config.json功能角度5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆