简体   繁体   English

从node.js切换到iisnode时要更改什么?

[英]what are the things to change when switching from node.js to iisnode?

I've been trying to run a node application on iisnode. 我一直试图在iisnode上运行节点应用程序。 this app runs on node.js smoothly and has no problem. 这个程序可以在node.js上流畅运行,没有问题。 however, i need to integrate this app to an asp.net application hence i've been trying to run this app on iis using iisnode! 但是,我需要将此应用程序集成到asp.net应用程序,因此我一直在尝试使用iisnode在iis上运行该应用程序! but i've been facing some difficulties! 但是我一直遇到一些困难! i was wondering is there anything that need to be changed in config or server.js file to make it work ? 我想知道是否需要在config或server.js文件中进行任何更改才能使其正常工作?

thanks ! 谢谢 !

The only required change in node app will be port number - use process.env.PORT value instead of specific numeric in you server.js/app.js as stated in the official /src/samples/express/hello.js (notice the last line): 节点应用程序中唯一需要的更改将是端口号 -使用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);

Also make sure that asp.net's web.config have sections for node (taken from /src/samples/express/web.config ): 还要确保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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM