如何在 IIS 中运行 emberJS 应用程序? [英] How to run emberJS application in IIS?

查看:21
本文介绍了如何在 IIS 中运行 emberJS 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Ember CLI 构建的 EmberJS 应用程序.为了部署我的应用程序,我在 Ember CLI 中使用了 ember build --release 命令,并将 /dist 文件夹中的输出复制到与 IIS 映射的文件夹中.一切似乎都运行良好.当您在 SPA 内导航时更新 url,从 Web 服务等获取数据.但是如果我尝试直接访问 localhost/someurl,我会收到 404 Not Found 错误.我猜这是因为 IIS 7 中的路由,但我怎样才能使它与 Ember 路由一起工作?

解决方案

我知道这个问题很老了,但我发现使用 IIS URL 重写模块(https://www.iis.net/downloads/microsoft/url-rewrite) 基本上模仿了 apache 的 mod_rewrite.

基本上,您在 web.config 中定义重写规则,您将其放置在放置到 IIS 目录中的 dist/* 文件旁边,然后进入城镇.

这是我的 web.config 中的重写规则块.

<预><代码><配置><system.webServer><重写><规则><rule name="CatchAll For Ember" patternSyntax="Wildcard" stopProcessing="true"><匹配 url="*"/><action type="重写" url="index.html"/><条件><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></条件></规则></规则></rewrite></system.webServer></配置>

如果您删除 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆