Опитвам се да разбера как да използвам node.js с jade в момента и не мога да го накарам да изтегли css stylesheet. Моят app.js изглежда така:
/* * Module dependencies */
var http = require("http"),
express = require('express') ,
stylus = require('stylus')
//create an app server
var app = module.exports = express.createServer();
app.configure(function(){
//set path to the views (template) directory
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(app.router);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(stylus.middleware({
debug: true,
src: __dirname + '/views',
dest: __dirname + '/public'
}));
app.use(express.static(__dirname + 'public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
//handle GET requests on /
app.get('/', function(req, res){res.render('index.jade');
});
//listen on localhost:3000
app.listen(3000);
Моят файл layout.jade изглежда така:
html
head
title= title
link(rel='stylesheet', href='/bg/stylesheets/style.css')
body!= body
И моята файлова структура е:
App
-node_modules
-public
-css
style.css
-img
-js
-views
-routes
-stylesheets
style.styl
index.jade
layout.jade
app.js
package.json
Уебсайтът се зарежда правилно, но таблицата със стилове не се зарежда.
express.static()
, липсва/
--__dirname + '/public'
-- така че вероятно се опитва да търси файлове в папкаApppublic
, която не съществува.path
модул също може да помогне за избягването на това:express.static(path.join(__dirname, 'public'))
. - person Jonathan Lonowski   schedule 02.02.2014require('path')
както сте сhttp
,express
и т.н., тъй като не е глобален в модули. - person Jonathan Lonowski   schedule 02.02.2014