felixrieseberg / ember-cli-azure-deploy

:wrench: Build Ember Cli Apps on Azure Websites
MIT License
19 stars 2 forks source link

How to set web.config for deep links? #14

Closed mattmazzola closed 8 years ago

mattmazzola commented 8 years ago

Hi,

(This is not really a bug so feel free to close if you think it's not applicable) If it's possible to fix I thought it might be good to integrate into the repo since I assume it's a common pitfall for other newcomers like myself.

After the application is deployed if I try to navigate to specific route instead of the home page I see this error in the browser: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Example: https://fakewebsite.azurewebsites.net/things/1 I think this has to do with IIS treating the path as looking for a folder / file when the intention was to load the normal index.html and load the ember app which would parse the url and transition to the route.

Example: https://fakewebsite.azurewebsites.net If I remove the path and reload the application, it loads as expected and then I can navigate to the route, but I would like to be able to deep link to it.

Is there a simple fix I can put in the web.config or one of the deploy files to solve this?

felixrieseberg commented 8 years ago

Yep, there is - you need to reroute all paths to index.js.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
    <handlers>
      <add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="index.js"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>