我试着用iisnode运行express。我遵循了提供的示例,但是当尝试使用带有基本示例的最新Express版本时,没有办法让它工作。
我得到了错误的Cannot GET /node/parislight/hello.js和其他时间,只是一个The webpage cannot be found。
我创建了一个从hello.js获取的特快专递文件(主快件文件)。
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中的表达式示例中提取)
<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中使用的App提供了所有必要的权限。
发布于 2015-11-20 11:20:50
它需要使用完整的路径:
app.get调用中指定的路径必须是请求的完整路径。
来源
现在看起来是这样:
app.get('/node/parislight/myapp/demo', function (req, res) {
res.send('Hello World!')
})通过以下方式加入:
http://localhost/node/parislight/myapp/demo
发布于 2016-08-23 14:04:00
您也可以使用文件末尾的catch all函数获取任何url,并发送200响应或发送您的特殊404页。注意:位置必须在所有其他指定的urls之后。
app.get('*', function (req, res) {
res.send('Hello World!')
})https://stackoverflow.com/questions/33825355
复制相似问题