gpt4 book ai didi

javascript - 无法在 node/express/pug 应用程序中获取 css

转载 作者:技术小花猫 更新时间:2023-10-29 11:36:43 26 4
gpt4 key购买 nike

我正在使用 Express 和 Pug(以前的 Jade)创建我的第一个 Node 应用程序。一切正常,除了让我的 css 文件在浏览器上运行。(错误 404:获取 http://localhost:3000/css/syles.css)

元素结构:

server.js
views
bag.pug
public
css
styles.css

我的服务器js文件:

const pug = require('pug');
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;

const inv = require('./api/pogoni/inventory');

// Set views path
app.set('views', path.join(__dirname, 'views'));
// Set public path
app.use(express.static(path.join(__dirname, 'public')));
// Set pug as view engine
app.set('view engine', 'pug');

// Player's index
app.get('/player', (req, res) => {
res.render('player', {
title: 'PLAYER Dashboard'
});
});

// Player's bag
app.get('/bag', (req, res) => {
inv.getInventory()
.then((inventory) => {
if(!inventory) {
throw new Error('Unable to fetch inventory.');
}
res.render('bag', {
title: 'PLAYER bag',
inventory
});
})
.catch((e) => {
res.status(500, {
error: e
});
});
});

// Start server
app.listen(port, () => {
console.log(`Server is up on port ${port}`);
});

包.哈巴狗

doctype html
html
head
meta(charset='UTF-8')
title #{title}
link(rel='stylesheet', href='/css/syles.css')

最佳答案

你打错了:syles 而不是 styles

doctype html
html
head
meta(charset='UTF-8')
title #{title}
link(rel='stylesheet', href='/css/styles.css')

关于javascript - 无法在 node/express/pug 应用程序中获取 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41051493/

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