css - 加载单独的 css 样式表(heroku nodejs)

标签 css node.js heroku

我无法在本地和 heroku 服务器上为 heroku 网络应用程序加载单独的 css 样式表。我最近从谷歌应用引擎迁移过来,我在那里加载样式表的方式工作得很好。我在这里做错了什么?任何帮助将不胜感激!!这是我的代码:

/app/server.js

var express = require("express");
var app = express();
app.use(express.logger());

var fs = require("fs");
var buf = fs.readFileSync("html/index.html");
var index = buf.toString();

app.get('/', function(request, response) {
    response.send(index);
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
    console.log("Listening on " + port);
});

/app/html/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Starters Singapore | Social Group Dating</title>
    <link rel="stylesheet" type="text/css" href="../css/index.css">
  </head>

  <body>
    <div id="testdiv">This is a test</div>
  </body>

</html>

/app/css/index.css

body{
    margin:0;
    text-align: left;
    background-color: #666666;
}

#testdiv{
    width: 50%;
    height: 50%;
    background-color: #00a1ec;
}

最佳答案

您正在使用 css 文件的相对路径。此路径是相对于服务器根目录而不是 html 文件的。我没有使用 Heroku NodeJS 的经验,但我认为路径应该是

/css/index.css

关于css - 加载单独的 css 样式表(heroku nodejs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17509076/

相关文章:

jquery - 如何创建一个 jQuery 新消息弹出对话框

html - 非 float div 的内部文本相对于前一个 float div 定位

Javascript 的 setExpression 是我最大的问题。任何解决这个问题的方法

css - 响应式网页设计和固定边距

javascript - iOS 上的事件 'onDeviceMotion' 有任何限制吗?

ruby-on-rails - rake 中止!加载错误 : no such file to load -- active_record/connection_adapters/postgresql/explain_pretty_printer

node.js - 如何使用非常流行的颜色模块使用 rgb 或 hex 表示来设置颜色?

javascript - 如何从通用 javascript 引用 React 类

Heroku 自定义域重写为 herokuapp URL

heroku 和 rabbitmq - 无法运行多个 worker dynos