我使用express 4.x和less-middlesware,我有一个主文件(把手):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example App</title>
<link rel="stylesheet" href="public/css/styles.css">
</head>
<body>
{{{body}}}
</body>
</html>
我的服务器看起来像这样:
var express = require('express');
var exphbs = require('express-handlebars');
var less = require('less-middleware');
var path = require('path');
var env = process.env.NODE_ENV || 'development';
var app = express();
app.set('views' , __dirname + '/server/views');
app.engine('.hbs', exphbs({
defaultLayout: 'main' ,
layoutsDir: 'server/views/layouts',
extname: '.hbs'
}));
app.set('view engine', '.hbs');
app.use(less(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
app.get('*' , function(req , res){
res.render('index', {message: 'Hi'});
});
var port = 3000;
app.listen(port);
console.log('Listening on port: ' + port);
页面服务正常,但我收到有关css的消息:
资源解释为样式表但使用MIME类型传输 text / html:&#34; http://localhost:3000/public/css/styles.css&#34;。
我缺少什么?