iisnode不会运行Express
我试图运行使用iisnode快递。 我遵循了所提供的示例,但是当尝试使用最新的Express版本和基本示例时,无法使其工作。
我得到的错误Cannot GET /node/parislight/hello.js
和其他时间,只是一个The webpage cannot be found
。
我创build了一个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中使用的应用程序池提供了所有必要的权限。
你可以在文件末尾使用catch all函数来获取任何url,并发送一个200响应或者发送你特殊的404页面。 注意:展示位置必须位于所有其他指定的url之后。
app.get('*', function (req, res) { res.send('Hello World!') })
它需要使用完整的path:
app.get调用中指定的path必须是请求的完整path。
资源
现在看起来像这样:
app.get('/node/parislight/myapp/demo', function (req, res) { res.send('Hello World!') })
通过以下方式join:
HTTP://本地主机/节点/ parislight / MYAPP /演示
- 如何sorting导致nodejs – mongodbsearch,但通过调用dynamic方法
- 使用React刷新浏览器历史logging路由器从我的API返callback用
- 刷新浏览器后,包含“hypen”的URL不会经过angular度$ routeProvider.when(),而直接请求服务器
- 简单的AJAX获取请求是“挂起”
- 在node.js中的JSON Zip Response
- 明确存在的function被确定为未定义的
- 当我刷新的时候,Webpack-dev-middleware会返回一个404
- 如何parsingNodeJS服务器中由ajax发送的数组/对象
- 如何捕获这个错误NodeJs / Express?