2

I'm new to sails.js and node.js, so the question might be trivial, but I couldn't find the answer. I have deployed my node.js app to a web site in IIS, so the app can be reached at http://example.com/myapp/. When browsing to http://myhost.com/myapp/app.js, I get http status 404 (Not found), because sail.jss is looking for URLs like http://myhost.com/images/logo.png, but this file is in fact located at http://myhost.com/myapp/.tmp/public/images/logo.png. This .tmp folder seems to be created on the fly by the framework.

Can someone shed some light on this?

[edit]

I have added rewrite rules in the web.config and it works much better. But it only works if I put the application at the root of my web site (acessing http://myhost.com/). If I put the application in a lower level (accessing through http://myhost.com/myApp), then the added rules do not seem to produce any effect.

Here is the web.config:

<handlers>
  <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>

   <rewrite>
       <rules>

            <rule name="StaticContent">
                 <action type="Rewrite" url="assets{REQUEST_URI}"/>
            </rule>

            <rule name="DynamicContent">
                 <conditions>
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                 </conditions>
                 <action type="Rewrite" url="app.js"/>
            </rule>

       </rules>
  </rewrite>

user957479
  • 491
  • 1
  • 5
  • 20
  • Maybe they are discussing your problem here: https://github.com/tjanczuk/iisnode/issues/298 .. or just don't use IIS for that. – Robin Oct 17 '14 at 14:20
  • Not sure what you are trying to access. Any files located in the assets folder can be accessed directly. If you want to access a js file, put it in assets/js folder. Similarly, images can be placed in assets/images – Mandeep Singh Oct 17 '14 at 14:22
  • how does your web.conf look like? Can you update your post with that? – Robin Oct 17 '14 at 17:25
  • Thanks all for the help. I have edited my post with web.confg and some findings that helped. Remaining problem is that it does not work if application is not in the root of my web site ! Probably the rules have to be adapted somehow but not success so far... – user957479 Oct 21 '14 at 09:00

2 Answers2

1

The key is to allow Express to handle all of the routing. The best way to do that is to route all traffic to app.js via iisnode (from: https://nodestream.wordpress.com/2015/11/24/sails-js-configuration-for-iis/):

<configuration>
  <system.webServer>
    <!-- Tell IIS to use the iisnode module to run your
         application -->
    <handlers>
      <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>
    <!-- Add iisnode with the @nodeProcessCommand line if
     you see the error: Make sure the node.exe executable
     is available at the location specified in the
     system.webServer/iisnode/@nodeProcessCommandLine element
     of web.config. -->
    <iisnode
       nodeProcessCommandLine="%ProgramFiles%\nodejs\node.exe"
    />
    <!-- Since behind the covers, Sails.js is just an express app
    rewrite all urls to processed by iisnode via app.js. This
    will sort out things like the routing to your public
    resources (images, js, styles) and all configured rest
    endpoints. -->
    <rewrite>
      <rules>
        <rule name="root">
          <match url=".*" />
          <action type="Rewrite" url="app.js" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
0

Well the .tmp folder is created by Grunt. You can reference the gruntfile and the task folder. The pipeline.js allows you to select files/folders for grunt to inject and spit out. You can easily change this to point to /images and /js folders.

tasks/pipline.js

module.exports.cssFilesToInject = cssFilesToInject.map(function(path) {
  return '.tmp/public/' + path; // Change this
});
module.exports.jsFilesToInject = jsFilesToInject.map(function(path) {
  return '.tmp/public/' + path; // Change this
});

Another solution I could think of, however I am not sure if IIS has it, is to do a rewrite rule. When a user goes to site.com/images, point them to .tmp/public/images. It is common to see that in Apache servers.

jemiloii
  • 24,594
  • 7
  • 54
  • 83
  • Hi, thx for your answer ! My apps seems to access the correct directory. I have indeed a rule that redirects to assets (or to .tmp/public to be compliant with Grunt), see my web.config. The problem comes from using a root site directory with subfolders and I can't see how to modify the routing in pipeline.js (it's not linked to routing subparts of .tmp/public but to route correctly the base root web site – user957479 Nov 02 '14 at 18:31