Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Angular agents based on scaffolding

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to configure Angular agents based on scaffolding". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Angular proxy configuration

Official website document https://angular.io/guide/build#using-corporate-proxy

Why do you do it?

Write an agent file and proxy the matching requests to other addresses to solve the cross-domain problem of local development.

How to configure it?

Create a proxy.config.js in the root directory

You can do the following configuration in this file

Add-- proxy-config proxy.config.js to the running project command of package.json

Configuration introduction

Const PROXY_CONFIG = [{context: ['/ api'], target: 'http://xxx', secure: false, changeOrigin: true, pathRewrite: {' ^ / api':',},},]; module.exports = PROXY_CONFIG

Context: path that needs to match

Target: the address to which the agent is represented

PathRewrite: rewrite the requested part of the path, which is an object, the key is the path to be rewritten by ^ +, and the value is the replacement path.

Secure: security settin

ChangeOrigin: changing sourc

Configure an instance

Such as http://localhost:4208/auth/login

Want to be an agent to

Http://www.baidu.com/news/login

It can be configured like this.

Const PROXY_CONFIG = [{context: ['/ auth/login'], target: 'http://www.baidu.com', pathRewrite: {' ^ / auth/login':'/ news/login',},},] module.exports = PROXY_CONFIG;Q: if there are two interfaces, one / api/cer/register and the other / 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,}

Using / api, anyone who matches this will take its proxy, but if a more accurate / api/cer/login is added in front of it, it will match it first and take this proxy.

This is the end of "how to configure Angular agents based on scaffolding". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report