return $r; } /** * @param int $page 页数 * @param int $pagesize 每页显示数量 * @return mixed */ function link_find($page = 1, $pagesize = 100) { $arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize); return $arr; } /** * @param $id * @return bool 返回FALSE失败 TRUE成功 */ function link_delete($id) { if (empty($id)) return FALSE; $r = link__delete(array('id' => $id)); link_delete_cache(); return $r; } //--------------------------kv + cache-------------------------- /** * @return mixed 返回全部友情链接 */ function link_get($page = 1, $pagesize = 100) { $g_link = website_get('friends_link'); if (empty($g_link)) { $g_link = link_find($page, $pagesize); $g_link AND website_set('friends_link', $g_link); } return $g_link; } // delete kv and cache function link_delete_cache() { website_set('friends_link', ''); return TRUE; } ?>javascript - Can't get css in nodeexpresspug app - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't get css in nodeexpresspug app - Stack Overflow

programmeradmin5浏览0评论

I'm creating my first Node app using Express and Pug (former Jade). Everything is working fine, except getting my css files running on the browser. (Error 404: GET http://localhost:3000/css/syles.css)

Project structure:

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

My server js file:

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

bag.pug

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

I'm creating my first Node app using Express and Pug (former Jade). Everything is working fine, except getting my css files running on the browser. (Error 404: GET http://localhost:3000/css/syles.css)

Project structure:

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

My server js file:

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

bag.pug

doctype html
html
    head
        meta(charset='UTF-8')
        title #{title}
        link(rel='stylesheet', href='/css/syles.css')
Share Improve this question asked Dec 9, 2016 at 1:03 nipnip 1,7071 gold badge12 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You have a typo: syles instead styles

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

评论列表(0)

  1. 暂无评论