javascript - 使用 Azure 应用服务部署的 Angular 应用找不到使用 ng serve 时找到的资产
问题描述
我有一个 Angular CLI 构建的应用程序,'src/app/text-gen/text-gen.component.ts' 中的脚本加载到 tensorflow.js 模型中:
this.model = await tf.loadLayersModel('../assets/models/model.json');
引用 'src/assets/models/model.json' 中的 JSON。
使用 Azure App Services 部署此应用程序时,一切正常,但由于某种原因,此 model.json 返回 404 Not Found:
查看 Kudu 控制台时,我可以在“site/wwwroot/assets/models/model.json”中看到 model.json。
此外,在“angular.json”中,my"outputPath"
设置为"dist"
.
我确信这是非常明显的事情——我对 Angular、web-dev、Azure 等很陌生——但我似乎无法弄清楚这一点!
谢谢!!!
编辑:model.json
在 Kudu 控制台中添加屏幕截图,我也尝试'/assets/models/model.json'
作为路径并收到相同的错误。
解决方案
多亏了这个问题,我才知道这一点。
在 web.config 文件中,我需要在标签<staticContent><mimeMap fileExtension=".json" mimeType="application/json" /></staticContent>
之前添加。<rewrite>
总共给出了一个如下所示的 web.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent><mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
对于像我这样对 Angular 不熟悉的人来说。通过将 web.config 文件添加到angular.json 中,可以将其包含在dist/
目录中,因此我的资产如下所示:"assets"
"assets": [
"src/favicon.ico",
"src/model.json",
"src/char2idx.json",
"src/web.config"
]
推荐阅读
- angular - 页面初始加载时显示两个菜单
- c# - Unity C# - 带有 LayerMask 的 Physics.Raycast 方法似乎不会忽略给定的图层
- tensorflow - DQN 的迁移学习
- node.js - nodejs sqlite3 查询返回空 - 无法理解异步
- javascript - 获取响应本机中的php文件时如何修复获取返回404?
- laravel - Laravel Eloquent:有什么方法可以得到改变模型的原始关系?
- c# - Azure Web Job BlobTrigger - 重置 Scaninfo 以触发现有 Blob 的功能
- highcharts - highchart升级后如何修复工具提示
- arduino - 有没有办法使用 Arduino CLI 将 sketch.ino 编译为 .bin 文件?
- c++11 - C ++,使用指针和运算符地址重新创建memset