samedi 28 février 2015

nodejs/jade/express in mvc: cannot get stylus to compile files

I was following this tutorial to set up proper MVC project with node.js, Express and Jade. It works great. I just have a problem with setting up Stylus and nib.


My filesystem:



/
| app
| controllers
| index.server.controller.js
| models
| routes
| index.server.routes.js
| views
| stylesheets
| style.styl
| index.jade
| config
| env
| config.js
| express.js
| node_modules
| ...
| public
| images
| scripts
| stylesheets
| style1.css
| package.json
| server.js


server.js:



var port = 8888
var express = require('./config/express')

var app = express()

app.listen(port)

console.log('server is running on port: ' + port)


express.js:



var express = require('express')
var stylus = require('stylus')
var nib = require('nib')

module.exports = function() {
var app = express()

app.set('views', './app/views')
app.set('view engine', 'jade')

require('../app/routes/index.server.routes.js')(app)

app.use(stylus.middleware({
src: __dirname + '/app/views',
dest: __dirname + '/public'
}))

app.use(express.static('./public'))

return app
}


index.server.routes.js:



module.exports = function(app) {
var index = require('../controllers/index.server.controller')

app.get('/', index.render)
}


index.server.controller.js:



exports.render = function(req, res) {
res.render('index', {
title: 'hello world',
header: 'hi tahr'
})
}


I know I don't even try to run nib here, it won't even compile .styl file. I tried thousands of different ways to actually add this middleware. I tried to add it before and after routers, statics etc.


Other files that might be relevant:



  • style1.css is just some random .css file to check if they are even loaded properly. Jade will load it fine.

  • config.js is empty.


As far as I understand it works like this: server.js asks express.js to initialize and configure itself and waits to get a finished express object.


Express asks for routers the index.server.routers.js file which in turn asks index.server.controller.js to do some stuff. It does its stuff, after it completes express.js can return app to server.js where it will start to listen on port 8888.


I know it might have something to do with the order in which I order my files, maybe because I render too soon or something... but those .styl files still should appear! Using debug: true won't show anything in the console and the only message there is "server is running on port: 8888".


Firefox developer tools are saying that style1.css loads properly while the query for style.css fails with 404 (since there is no such filed compiled by Stylus).


After hours (literally) spent I give up and ask for your help, stackoverflowers.


Aucun commentaire:

Enregistrer un commentaire