【问题标题】:My iisnode setup wont serve the static files我的 iisnode 设置不会提供静态文件
【发布时间】:2015-02-14 04:02:21
【问题描述】:

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

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 

【问题讨论】:

  • ./pro/Public 下的文件夹结构是什么样的?
  • @TimothyStrimple 它包含 .css 和 .js 文件以及一些 png。

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


【解决方案1】:

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

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

【讨论】:

  • 这个答案似乎没有解决我的问题我仍然得到我的错误! ://
  • 好像我有另一个错误我不应该使用'./pro/Public'首先我应该只使用'./Public'。我仍然没有得到静态文件,现在错误的投射方式有所不同,它说“GET localhost/cssvolos.css localhost/:7”,当我检查开发人员工具并检查 .css 和 .js 文件中的网络选项卡时,它说键入“text/html”而不是 css 或 js。我认为所有的路径都是正确的,还有什么可能是错误的吗?
  • 你在监听 80 端口吗?如果您尝试直接查看该文件会怎样?
  • 我监听端口 process.env.port,当我尝试访问该文件时,我得到 "Cannot GET /pro/public/file.css" 。有什么想法吗?
  • 在我的本地主机设置中一切正常。IIS 设置可能有什么问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-27
  • 1970-01-01
  • 2014-11-24
  • 1970-01-01
  • 1970-01-01
  • 2017-08-04
  • 2012-06-15
相关资源
最近更新 更多