Angular8:生产环境无法加载图片。出现 403 错误,因为相对 url 路径被附加到 assets/images 路径中
Angular 8: Production environment not able to load images. Give a 403 error, as relative url path gets appended in the assets/images path
我在本地环境中的 Angular 应用程序能够加载图像,但在通过 AWS 代码构建部署到生产环境后,出现 403 错误。
以下是构建命令:ng build --configuration=qa --aot=false --base-href=
错误如下:
虽然,如果我只是尝试浏览图片来自:
https://mfqa.credivia.com/assets/images/logo.png 而不是
https://mfqa.credivia.com/borrower/assets/images/logo.png,图像已加载。
问题:
尝试检索图像时附加了相对 url 路径。
已检查:
- Dist 文件夹在根目录下包含 [assets] 文件夹
- base href="/"
- 提供的图片路径为:img src="assets/images/loading.gif"
- 以下来自 angular.json 的代码片段:
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
感谢您的回复。问题是在 prod build 命令中设置 --base-href 时。
我在本地环境中的 Angular 应用程序能够加载图像,但在通过 AWS 代码构建部署到生产环境后,出现 403 错误。
以下是构建命令:ng build --configuration=qa --aot=false --base-href=
错误如下:
虽然,如果我只是尝试浏览图片来自: https://mfqa.credivia.com/assets/images/logo.png 而不是 https://mfqa.credivia.com/borrower/assets/images/logo.png,图像已加载。
问题: 尝试检索图像时附加了相对 url 路径。
已检查:
- Dist 文件夹在根目录下包含 [assets] 文件夹
- base href="/"
- 提供的图片路径为:img src="assets/images/loading.gif"
- 以下来自 angular.json 的代码片段:
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
感谢您的回复。问题是在 prod build 命令中设置 --base-href 时。