This article will introduce to you how to configure the Angular proxy (proxy) based on scaffolding. I hope it will be helpful to you!
[Related tutorial recommendation: "angular tutorial"]
Write a proxy file to proxy matching requests to other addresses to solve cross-domain problems in local development.
proxy.config.js in the root directory
--proxy-config proxy.config.js
## to the running project command of package.json
const PROXY_CONFIG = [ { context: ['/api'], target: 'http://xxx', secure: false, changeOrigin: true, pathRewrite: { '^/api': '', }, }, ]; module.exports = PROXY_CONFIG;
: The path that needs to be matched
: The address to be proxied to
: The requested part path rewriting, it is an object, the key is
^ the path to be rewritten, and the value is the path to be replaced.
: Security settings
: Change origin
http://localhost:4208/auth/login
http://www.baidu. com/news/login
const PROXY_CONFIG = [ { context: ['/auth/login'], target: 'http://www.baidu.com', pathRewrite: { '^/auth/login': '/news/login', }, }, ] module.exports = PROXY_CONFIG;
, the other A
/api/cer/login, how can I proxy the two interfaces to different addresses?
{ context: ['/api/cer/login'], target: 'xxx1', secure: false, changeOrigin: true, }, { context: ['/api'], target: 'xxx2', secure: false, },
/api, as long as it matches this, it will go through its proxy, but if you add a more accurate
/api/cer in front of it /login will match it first and use this proxy.
More usage updates on github:https://github.com/deepthan/blog-angularMore programming related knowledge, Please visit:
Introduction to Programming! !
The above is the detailed content of A brief analysis of how to configure Angular proxy based on scaffolding. For more information, please follow other related articles on the PHP Chinese website!