2

我一直在尝试在 iisnode 上运行节点应用程序。这个应用程序在 node.js 上运行流畅,没有问题。但是,我需要将此应用程序集成到 asp.net 应用程序中,因此我一直在尝试使用 iisnode 在 iis 上运行此应用程序!但我一直面临一些困难!我想知道是否需要在 config 或 server.js 文件中更改任何内容才能使其正常工作?

谢谢 !

4

1 回答 1

1

节点应用程序中唯一需要更改的是端口号- 使用process.env.PORT值而不是 server.js/app.js 中的特定数字,如官方/src/samples/express/hello.js中所述(注意最后一行):

var express = require('express');

var app = express.createServer();

app.get('/node/express/myapp/foo', function (req, res) {
    res.send('Hello from foo! [express sample]');
});

app.get('/node/express/myapp/bar', function (req, res) {
    res.send('Hello from bar! [express sample]');
});

app.listen(process.env.PORT);

还要确保 asp.net 的web.config有节点部分(取自/src/samples/express/web.config):

<configuration>
  <system.webServer>

    <!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module -->

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

    <!-- use URL rewriting to redirect the entire branch of the URL namespace
    to hello.js node.js application; for example, the following URLs will 
    all be handled by hello.js:

        http://localhost/node/express/myapp/foo
        http://localhost/node/express/myapp/bar

    -->

    <rewrite>
      <rules>
        <rule name="myapp">
          <match url="myapp/*" />
          <action type="Rewrite" url="hello.js" />
        </rule>
      </rules>
    </rewrite>

  </system.webServer>
</configuration>
于 2013-11-04T01:54:18.223 回答