在使用grunt运行服务器时,收到错误,因为无法GET /
server.js
var express = require('express');
var app = express();
var port = process.env.PORT || 2323;
app.use(express.static(__dirname + '/server'));
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendfile('./server/views/index.html');
});
app.listen(port, function(){
console.log('server is running on ' + port);
});
Gruntfile.js
module.exports = function(grunt){
var modRewrite = require('connect-modrewrite');
var serveStatic = require('serve-static');
grunt.initConfig({
connect: {
server: {
options: {
port: 2323,
base: 'views',
keepalive: true,
livereload: 35729,
hostname: 'localhost',
open: true,
middleware: function (connect) {
return [
modRewrite(['^[^\\.]*$ /index.html [L]']),
connect().use('/', serveStatic('/views'))
];
}
}
}
}
// configure connect
});
//load nodemon
grunt.loadNpmTasks('grunt-contrib-connect');
//register the nodemon task when we run grunt
grunt.registerTask('default', ['connect:server']);
};
我不知道我的grunt文件代码是对还是错 实际上是新的咕噜声,我不知道该怎么做,在运行grunt时遇到无法获取/ 此错误。
答案 0 :(得分:0)
您在Grunt中运行的连接服务器的设置中只有一个错误:
connect().use('/', serveStatic('/views'))
应该是
connect().use('/', serveStatic('./server/views'))