Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explain proxy.config.json features angular 5

Tags:

angular

"/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

thank you for help

like image 651
Prasanna Avatar asked Jul 01 '18 17:07

Prasanna


1 Answers

   "/api/*": {
      "target": "https://localhost:8000",
      "secure": false,
      "logLevel": "debug",
      "pathRewrite": {
        "^/api": ""
      },
      "changeOrigin": true
    }
  1. target:"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.

  3. "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).

  4. "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

  5. "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 provided in this package is from underlying node-http-proxy

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

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.

like image 163
Vikas Avatar answered Sep 29 '22 03:09

Vikas