美文网首页Angular
Angular 项目配置代理与跨域相关

Angular 项目配置代理与跨域相关

作者: survivorsfyh | 来源:发表于2022-06-10 11:37 被阅读0次

    调试 Angular 新项目的时候配置好 proxy-config 后启动发起接口请求但依然抛出了 404 的异常,一波摸索后发现 angular.json 文件内缺少了对代理的配置导致,具体如下:

    一.配置 angular.json => options => proxyConfig

    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "theory-pe:build",
        "proxyConfig": "proxy-config.json"
      },
      "configurations": {
        "production": {
          "browserTarget": "theory-pe:build:production"
        },
        "development": {
          "browserTarget": "theory-pe:build:development"
        }
      },
      "defaultConfiguration": "development"
    },
    

    二.配置 proxy-config.json

    {
      "/api": {
        "target": "http://192.168.8.209:9001",
        "secure": false,
        "logLevel": "debug",
        "changeOrigin": true
      },
    }
    

    以上便是此次分享的全部内容,希望能对大家有所帮助!

    相关文章

      网友评论

        本文标题:Angular 项目配置代理与跨域相关

        本文链接:https://www.haomeiwen.com/subject/ihxbmrtx.html