尝试使用代理配置部署 Angular 17 Web 应用程序,但它在生产中不起作用

问题描述 投票:0回答:1

我对这个错误真的一无所知。在本地开发模式下,它可以工作。但在生产中,请求返回网页而不是 RSS 提要,就好像路径错误并返回根(而不是主页)。

注意:这是我尝试部署的一个 Firebase 云项目。

我的

proxy.config.json
看起来像这样:

{
    "/rss": {
         "target": "https://baladoquebec.ca/podcast-name",
         "secure": false,
         "changeOrigin": true
    }
}

angular.json
看起来像:

"serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
        "proxyConfig": "proxy.conf.json"
    },
    "configurations": {
        "production": {
            "buildTarget": "halo-comm:build:production"
        },
        "development": {
            "buildTarget": "halo-comm:build:development"
        }
    },
    "defaultConfiguration": "development"
},

http.get
函数如下所示:

getFeedList(): Observable<any> {
    return this.http.get('/rss', { responseType: 'text' })
        .pipe(
            map(this.extractFeedList),
            catchError(this.handlerError)
        );
}

有没有办法调试或添加跟踪来了解代理的工作原理?

更新:

我发现在

firebase.json
中,我可以在
headers
redirects
上添加配置。到目前为止还没有成功,但正在研究这个解决方案。

更新#2:

当我点击重定向链接https://mydomain.app/rss时,它会重定向到开头提到的网址。

angular proxy production-environment
1个回答
0
投票

如果我错了,请纠正我,但

proxy.config.json
proxy server
仅适用于本地环境,并且仅用户可以编码、调试或测试应用程序。

在生产或多个“环境”中工作时,您需要设置环境文件并为

angular.json
中的每个环境构建配置文件。现在,应该在 ENV 中指定
domianBaseURL
your backend path
,并且编写 API 拦截器以在生产过程中使用生产模式标志进行切换也可以。

可以从这里获取参考 https://angular.io/guide/build#configure-environment-specific-defaults

希望这有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.