我的iisnode设置不会提供静态文件

时间:2014-12-15 22:45:14

标签: node.js iis server static-files iisnode

我的设置有什么问题?请记住我使用快递。

web.config文件:

<handlers>
  <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>

<rewrite>
  <rules>
    <rule name="myapp">
      <match url="/*" />
      <action type="Rewrite" url="app.js" />
    </rule>
  </rules>
</rewrite>

,app.js如下:

var express = require('express');
var app = express();
var server = http.createServer(app).listen(process.env.port);

app.use(express.static(__dirname + '/pro/Public'));

app.get('/pro',function(req,res) {
 res.sendfile(__dirname + '/yoyo.html');
 res.end;
});

并且html具有如下经典布局:

<link rel="stylesheet" type="text/css" href="cssKtelVolouOsm.css">
<script type="text/javascript" src="javascriptKtelVolouOsm.js"></script>

我收到以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost/cssKtelVolouOsm.css 


Failed to load resource: the server responded with a status of 404 (Not Found)      http://localhost/javascriptKtelVolouOsm.js 

1 个答案:

答案 0 :(得分:2)

如果这些文件实际存在于./pro/Public下,那么这很可能是由于在html中使用相对URL造成的。试试这个。

<link rel="stylesheet" type="text/css" href="/cssKtelVolouOsm.css">
<script type="text/javascript" src="/javascriptKtelVolouOsm.js"></script>