我正在为现有项目实施手写笔。我已下载'stylus'
和nib
个模块。在我实现两者之后,中间件根本不调用编译函数。我没有收到任何错误。
我相信,我所放置的某些顺序可能是错误的,或者某些其他方法会使编译函数发生错误。
任何人请帮我解决这个问题吗?
这是我的app.js文件功能:
var
express = require('express'),
cons = require('consolidate'),
http = require('http'),
stylus = require('stylus'),
nib = require('nib'),
path = require('path');
//------
var
fs = require("fs"),
app = express();
//adding compile function and compress
function compile(str, path) {
console.log('path is ' + path);//I am not getting any console
return stylus(str)
.set('filename', path)
.set('compress', true)
.use(nib());
}
// assign the underscore engine to .html files
app.engine('html', cons.underscore);
// all environments
app.set('port', process.env.PORT || 5000);
app.set('view engine', 'jade');
app.set('views', __dirname + '/ui');
// app.set('env', 'development');
//app.register('.html', require('jade'));
//app.engine('html', require('ejs').renderFile);
app.use(express.favicon());
// app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
// app.use(app.router);
//adding middleware for sytlus
app.use(stylus.middleware({ // i am using the midware here / what is wrong?
src: __dirname + '/ui',
compile:compile,
compress: true
}));
// // development only
// if ('development' === app.get('env')) {
// app.use(express.errorHandler());
// }
require('amdefine/intercept');
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
//var amdRequire = require(__dirname + "/ui/tests/config/test");
//console.log("amdRequire ========== " + amdRequire);
app.all('*', function (req, res, next) {
if (req.xhr) {
//console.log("req.path ==== " + req.path);
var filePath = __dirname + "/ui/restResponses" + req.path + "/" + req.method;
console.log("xhr path ------- " + filePath);
if (req.method === "GET") {
for (var g in req.query) {
if (req.query.hasOwnProperty(g)) {
console.log("GET::: req.query." + p + ": " + req.query[p] );
}
}
} else if (req.method === "POST") {
for (var p in req.body) {
if (req.body.hasOwnProperty(p)) {
console.log("POST::: req.body." + p + ": " + req.body[p] );
}
}
}
var jsFile = require(filePath);
var response = jsFile(req, res, next);
/*define([filePath], function (dependency) {
console.log("dependency ==" + dependency);
});*/
res.send(response);
} else {
next();
}
});
app.use(express.static(path.join(__dirname, 'ui')));
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
答案 0 :(得分:2)
从基础开始:您的HTML是否正确引用了样式表?浏览器是否为样式表发送了GET?浏览器对样式表的GET请求的URL是什么?鉴于您的文件系统布局,您确定URL映射到文件系统吗?还可以在环境中使用DEBUG=express:router
运行您的应用。您还可以使用除了记录req.path
之外什么都不做的中间件,然后拨打next()
来帮助您跟踪事情。