如何在IIS中运行emberJS应用程序? [英] How to run emberJS application in IIS?
问题描述
要部署我的应用程序,我使用Ember CLI使用
ember build --release
命令,并从 / dist
文件夹放入与IIS映射的文件夹。 一切似乎都很好。当您在SPA内部导航时,URL被更新,数据从Web服务等获取。但是,如果我尝试直接访问
localhost / someurl
,我会收到404 Not Found错误。我猜这是因为IIS 7中的路由,但是我该如何使用Ember路由?我知道这个问题很旧,但是我发现使用IIS URL Rewrite模块( https://www.iis.net/downloads/microsoft/url-rewrite ),基本上模仿apache的mod_rewrite。
基本上你定义重写在web.config中的规则,将您放在IIS目录中的dist / *文件旁边放置,然后去镇上。
这是我的web.config中的重写规则块。
<结构>
< system.webServer>
< rewrite>
< rules>
< rule name =CatchAll For EmberpatternSyntax =通配符stopProcessing =true>
< match url =*/>
< action type =Rewriteurl =index.html/>
<条件>
< add input ={REQUEST_FILENAME}matchType =IsFilenegate =true/>
< add input ={REQUEST_FILENAME}matchType =IsDirectorynegate =true/>
< / conditions>
< / rule>
< / rules>
< / rewrite>
< /system.webServer>
< / configuration>
如果您删除IsDirectory检查,那么它仍然会使用IIS的404作为坏目录。
这允许您在IIS中托管ember应用程序,而不使用/#/技术。
I have an EmberJS application that is built using Ember CLI.
To deploy my application I used the ember build --release
command with Ember CLI, and copied the output from the /dist
folder into the folder that is mapped with IIS.
Everything seems to work fine. The url is updated when you navigate inside the SPA, data is fetched from Web Service etc. BUT if I try to access localhost/someurl
directly, I get a 404 Not Found error. I'm guessing this is because of the routing in IIS 7, but how can I make this work with Ember routing?
I know this question is old but i found a very nice solution to the problem using the IIS URL Rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite) which basically mimic's apache's mod_rewrite.
Basically you define the rewrite rules in a web.config you place along side the dist/* files you dropped into an IIS directory and then go to town.
Here is my rewrite rule block in my web.config.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="CatchAll For Ember" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="index.html" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If you remove the IsDirectory check then it will still use IIS's 404 for bad directories.
This allows you to host ember applications in IIS without using the /#/ technique.
这篇关于如何在IIS中运行emberJS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!