iisnode将无法运行Express [英] iisnode won't run Express
问题描述
我正在尝试使用iisnode运行express.我按照提供的示例进行操作,但是当尝试将最新的Express版本与一个基本示例一起使用时,无法使其正常工作.
I'm trying to run express using iisnode. I followed the examples provided but when trying to use the latest Express version with a basic example, there's no way to make it work.
我收到错误Cannot GET /node/parislight/hello.js
,有时是The webpage cannot be found
.
我创建了一个hello.js
文件(主要快递文件),该文件取自快递文档.
My created a hello.js
file (main express file) taken from the express docs.
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
var server = app.listen(process.env.PORT, function () {
var host = server.address().address
var port = server.address().port
console.log('Example app listening at http://%s:%s', host, port)
})
我添加了必要的web.config
文件(从iisnode中的快速示例中提取)
I added the necessary web.config
file (extracted from the express example within iisnode)
<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>
我为IIS中使用的应用程序池授予了所有必要的权限.
I gave all the necessary permissions to the used App Pool in IIS.
推荐答案
它需要使用完整路径:
app.get调用中指定的路径必须是请求的完整路径.
The path specified in app.get calls must be the full path of the request.
现在看起来像这样:
app.get('/node/parislight/myapp/demo', function (req, res) {
res.send('Hello World!')
})
通过以下方式进行访问:
Acceding to it through:
这篇关于iisnode将无法运行Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!