admin管理员组文章数量:1023758
I have an Angular CLI built app, a script in 'src/app/text-gen/text-genponent.ts' loads in a tensorflow.js model with:
this.model = await tf.loadLayersModel('../assets/models/model.json');
Referring to a JSON in 'src/assets/models/model.json'.
When deploying this app with Azure App Services everything works but for some reason this model.json returns 404 Not Found:
When looking at the Kudu Console I can see model.json in 'site/wwwroot/assets/models/model.json'.
Also, in 'angular.json', my "outputPath"
is set to "dist"
.
I'm sure this is something very obvious - I'm very new to Angular, web-dev, Azure etc - but I can't seem to figure this one out!
Thanks!!!
Edit: Adding a screenshot of model.json
in the Kudu console, I also tried '/assets/models/model.json'
as the path and received the same error.
I have an Angular CLI built app, a script in 'src/app/text-gen/text-gen.ponent.ts' loads in a tensorflow.js model with:
this.model = await tf.loadLayersModel('../assets/models/model.json');
Referring to a JSON in 'src/assets/models/model.json'.
When deploying this app with Azure App Services everything works but for some reason this model.json returns 404 Not Found:
When looking at the Kudu Console I can see model.json in 'site/wwwroot/assets/models/model.json'.
Also, in 'angular.json', my "outputPath"
is set to "dist"
.
I'm sure this is something very obvious - I'm very new to Angular, web-dev, Azure etc - but I can't seem to figure this one out!
Thanks!!!
Edit: Adding a screenshot of model.json
in the Kudu console, I also tried '/assets/models/model.json'
as the path and received the same error.
-
Probably should be
'/assets/models/model.json'
. You can test this by tryinghttp://meditations-ai.azurewebsite/assets/models/model.json
in your browser – peinearydevelopment Commented Jul 15, 2020 at 17:11 -
@peinearydevelopment I tried this but it didn't work,
https://meditations-ai.azurewebsite/assets/models
works but with an access denied error 403 but typing the full path es with 404 not found error - despitemodel.json
being in that location - I've added a screenshot of it's location in SCM/Kudu – James Briggs Commented Jul 15, 2020 at 18:47
1 Answer
Reset to default 8I figured this out thanks to this question here.
In the web.config file, I needed to add <staticContent><mimeMap fileExtension=".json" mimeType="application/json" /></staticContent>
just before the <rewrite>
tag. Altogether giving a web.config file that looks like this:
<?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>
For anyone reading this in the future who is new to Angular like myself. The web.config file can be included within the dist/
directory by adding it to "assets"
inside angular.json, so my assets look like this for example:
"assets": [
"src/favicon.ico",
"src/model.json",
"src/char2idx.json",
"src/web.config"
]
I have an Angular CLI built app, a script in 'src/app/text-gen/text-genponent.ts' loads in a tensorflow.js model with:
this.model = await tf.loadLayersModel('../assets/models/model.json');
Referring to a JSON in 'src/assets/models/model.json'.
When deploying this app with Azure App Services everything works but for some reason this model.json returns 404 Not Found:
When looking at the Kudu Console I can see model.json in 'site/wwwroot/assets/models/model.json'.
Also, in 'angular.json', my "outputPath"
is set to "dist"
.
I'm sure this is something very obvious - I'm very new to Angular, web-dev, Azure etc - but I can't seem to figure this one out!
Thanks!!!
Edit: Adding a screenshot of model.json
in the Kudu console, I also tried '/assets/models/model.json'
as the path and received the same error.
I have an Angular CLI built app, a script in 'src/app/text-gen/text-gen.ponent.ts' loads in a tensorflow.js model with:
this.model = await tf.loadLayersModel('../assets/models/model.json');
Referring to a JSON in 'src/assets/models/model.json'.
When deploying this app with Azure App Services everything works but for some reason this model.json returns 404 Not Found:
When looking at the Kudu Console I can see model.json in 'site/wwwroot/assets/models/model.json'.
Also, in 'angular.json', my "outputPath"
is set to "dist"
.
I'm sure this is something very obvious - I'm very new to Angular, web-dev, Azure etc - but I can't seem to figure this one out!
Thanks!!!
Edit: Adding a screenshot of model.json
in the Kudu console, I also tried '/assets/models/model.json'
as the path and received the same error.
-
Probably should be
'/assets/models/model.json'
. You can test this by tryinghttp://meditations-ai.azurewebsite/assets/models/model.json
in your browser – peinearydevelopment Commented Jul 15, 2020 at 17:11 -
@peinearydevelopment I tried this but it didn't work,
https://meditations-ai.azurewebsite/assets/models
works but with an access denied error 403 but typing the full path es with 404 not found error - despitemodel.json
being in that location - I've added a screenshot of it's location in SCM/Kudu – James Briggs Commented Jul 15, 2020 at 18:47
1 Answer
Reset to default 8I figured this out thanks to this question here.
In the web.config file, I needed to add <staticContent><mimeMap fileExtension=".json" mimeType="application/json" /></staticContent>
just before the <rewrite>
tag. Altogether giving a web.config file that looks like this:
<?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>
For anyone reading this in the future who is new to Angular like myself. The web.config file can be included within the dist/
directory by adding it to "assets"
inside angular.json, so my assets look like this for example:
"assets": [
"src/favicon.ico",
"src/model.json",
"src/char2idx.json",
"src/web.config"
]
本文标签:
版权声明:本文标题:javascript - Angular app deployed with Azure App Services cannot find an asset which it finds when using ng serve - Stack Overfl 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745595843a2158162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论