gpt4 book ai didi

css - Node.js 加载 css

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:05 24 4
gpt4 key购买 nike

我的文件夹:

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');
});

索引.html:

<link rel="stylesheet" type="text/css" href="/public/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/public/css/style.css">

当我在没有服务器的情况下使用谷歌浏览器打开 index.html 时,CSS 有效。当我使用 node.js 时,CSS 未加载。

最佳答案

express.static() 直接在根目录上提供其文件夹的内容

因此,public/ 不是 URL 的一部分。

关于css - Node.js 加载 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47400656/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com