Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run emberJS application in IIS?

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?

like image 865
Karoline Brynildsen Avatar asked Aug 25 '14 08:08

Karoline Brynildsen


People also ask

How do I deploy Ember app?

To deploy an Ember application simply transfer the output from ember build to a web server. This can be done with standard Unix file transfer tools such as rsync or scp . There are also services that will let you deploy easily.


1 Answers

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.

like image 177
Chris Rice Avatar answered Oct 15 '22 09:10

Chris Rice