[英]Node.js Loading css
My folders: 我的文件夹:
server.js
index.html
-public
--css
--ses.scss
--style.css
Server js: 服务器js:
var express = require('express');
var path = require('path');
var publicPath = path.resolve(path.join(__dirname, 'public'));
var app = express();
var http = require('http').Server(app);
var fs = require('fs');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function (req, res) {
res.sendfile('./index.html');
});
http.listen(3000, function () {
console.log('listening on *:3000');
});
Index.html: index.html的:
<link rel="stylesheet" type="text/css" href="/public/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/public/css/style.css">
CSS works when I open index.html with google chrome without server.When I use node.js CSS isn't loading. 当我在没有服务器的情况下使用google chrome打开index.html时,CSS可以工作。当我使用node.js时,CSS无法加载。
express.static()
serves the contents of its folder directly on the root. express.static()
直接在根目录上提供其文件夹的内容 。
Therefore, public/
is not part of the URL. 因此,
public/
不是URL的一部分。
Node : 节点:
app.use("/css",express.static(path.join(__dirname, 'public/css')));
css : css:
<link rel="stylesheet" type="text/css" href="/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/css/style.css">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.