[英]Node.js Loading css
我的文件夹:
server.js
index.html
-public
--css
--ses.scss
--style.css
服务器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的:
<link rel="stylesheet" type="text/css" href="/public/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/public/css/style.css">
当我在没有服务器的情况下使用google chrome打开index.html时,CSS可以工作。当我使用node.js时,CSS无法加载。
express.static()
直接在根目录上提供其文件夹的内容 。
因此, public/
不是URL的一部分。
节点:
app.use("/css",express.static(path.join(__dirname, 'public/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.