0

我刚开始使用 node,我正在尝试使用 express jam 和 stylus 包启动并运行它。我想我已经正确设置了它,但是 CSS 文件没有被编译,并且在发出对样式表的请求时,我一直收到 404 not found 响应。

这是我的服务器

  /*
  * Module dependencies
  */
var express = require('express'),
   stylus = require('stylus'),
   nib = require('nib');
   var app = express();

function compile(str, path) {
    return stylus(str)
        .set('filename', path)
        .use(nib());
}
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(stylus.middleware({
src: __dirname + '/public/stylesheets',
compile: compile
}));

app.use(express.static(__dirname + '/public'));

/* Routes */

app.get('/', function (req, res) {
res.render('index',
  { title : 'Home' }
 )
})


/* Start the server */

app.listen(3000);

console.log('listening on port 3000');

和我的 layout.jade 文件

!!!5
html
 head
   title #{title} - My Site
   link(rel='stylesheet', href='stylesheets/style.css')
 body
  header
  h1 My Site
   .container
     .main-content
       block content
  .sidebar
    block sidebar
  footer
    p Running on node with Express, Jade and Stylus
4

1 回答 1

0

弄清楚了

https://github.com/LearnBoost/stylus/issues/122

对 /css/style.css 的请求解释为 /src/css/style.styl

于 2013-08-01T19:28:26.267 回答