我一直在尝试在iisnode上运行节点应用程序。这个应用程序在node.js上顺利运行,没有问题。但是,我需要将此应用程序集成到asp.net应用程序,因此我一直在尝试使用iisnode在iis上运行此应用程序!但我一直面临一些困难!我想知道是否有任何需要在config或server.js文件中更改以使其工作?
谢谢!
答案 0 :(得分:1)
节点应用中唯一需要的更改是端口号 - 使用process.env.PORT
值代替您在server.js / app.js中的特定数字,如官方{{3 (注意最后一行):
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/hello.js):
<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>