2

私は Sails.js と node.js を初めて使用するので、質問は些細なことかもしれませんが、答えが見つかりませんでした。node.js アプリを IIS の Web サイトにデプロイしたので、アプリには でアクセスできますhttp://example.com/myapp/。を参照すると、 sail.jss が のような URL を探しているため、http://myhost.com/myapp/app.jshttp ステータスが表示されますが、このファイルは実際には にあります。このフォルダーは、フレームワークによってその場で作成されるようです。404 (Not found)http://myhost.com/images/logo.pnghttp://myhost.com/myapp/.tmp/public/images/logo.png.tmp

誰かがこれに光を当てることができますか?

[編集]

web.config に書き換えルールを追加したところ、はるかにうまく機能します。ただし、アプリケーションを Web サイトのルート ( http://myhost.com/にアクセス)に配置した場合にのみ機能します。アプリケーションを下位レベル ( http://myhost.com/myAppからアクセス) に配置すると、追加されたルールは何の効果ももたらさないようです。

ここに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>

4

2 に答える 2

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>
于 2015-11-24T15:41:50.407 に答える
0

.tmp フォルダーは Grunt によって作成されます。gruntfile と task フォルダーを参照できます。Pipeline.js を使用すると、grunt が注入および吐き出すファイル/フォルダーを選択できます。これを /images および /js フォルダーを指すように簡単に変更できます。

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
});

私が考えることができる別の解決策ですが、IIS にそれがあるかどうかはわかりませんが、書き換えルールを実行することです。ユーザーが site.com/images にアクセスするときは、.tmp/public/images を参照してください。これは、Apache サーバーでよく見られます。

于 2014-10-29T16:36:49.483 に答える