Kar*_*sen 8 iis-7 ember.js ember-cli
我有一个使用Ember CLI构建的EmberJS应用程序.为了部署我的应用程序,我在ember build --releaseEmber CLI中使用了该命令,并将该/dist文件夹的输出复制到与IIS映射的文件夹中.一切似乎都很好.当你在SPA中导航,数据从Web服务等获取时,网址会更新.但是如果我尝试localhost/someurl直接访问,我会收到404 Not Found错误.我猜这是因为IIS 7中的路由,但我如何使用Ember路由工作呢?
Chr*_*ice 10
我知道这个问题已经过时了但是我发现使用IIS URL重写模块(https://www.iis.net/downloads/microsoft/url-rewrite)解决了这个问题非常好的解决方案,该模块基本上模仿了apache的mod_rewrite.
基本上,您在web.config中定义重写规则,将您放在IIS目录中的dist/*文件放在一起,然后转到城镇.
这是我的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>
Run Code Online (Sandbox Code Playgroud)
如果删除IsDirectory检查,它仍将使用IIS的404作为坏目录.
这允许您在不使用/#/技术的情况下在IIS中托管ember应用程序.
最简单的办法让得到这个在IIS上工作,并在IIS一样Sammy.js类似方式与其它航线框架的工作,是包括在这样的URL的哈希 http://0.0.0.0:4200/#/your-route/
在EmberJS中,这是通过修改应用程序路由器来实现的:
var Router = Ember.Router.extend({
location: 'hash'
});
Run Code Online (Sandbox Code Playgroud)
在您的情况下,因为您正在使用ember-cli,所以您修改了environment.config文件:
var ENV = {
...
locationType: 'hash'
... };
Run Code Online (Sandbox Code Playgroud)