2015-11-20 101 views
1

我想使用iisnode運行express。我遵循了所提供的示例,但是當嘗試使用最新的Express版本和基本示例時,無法使其工作。iisnode不會運行Express

我收到錯誤Cannot GET /node/parislight/hello.js和其他時間,只是一個The webpage cannot be found

我創建了一個hello.js文件(主要快速文件),取自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內從快車例如萃取)

<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。

回答

1

它需要使用完整路徑:

在app.get調用指定的路徑必須是請求的完整路徑。

Source

現在看起來像這樣:

app.get('/node/parislight/myapp/demo', function (req, res) { 
    res.send('Hello World!') 
}) 

因加入它:

http://localhost/node/parislight/myapp/demo

2

您可以ü在你的文件末尾添加一個捕獲所有函數以獲取任何URL併發送200響應或發送你的特殊404頁面。注意:展示位置必須位於所有其他指定的網址之後。

app.get('*', function (req, res) { 
    res.send('Hello World!') 
})