【发布时间】:2016-02-26 19:20:24
【问题描述】:
在使用 grunt 运行服务器时,出现无法获取的错误 /
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-file 代码是对还是错 实际上是新的 grunt,我不知道该怎么做,运行 grunt 时遇到 Cannot GET / 这个错误。
【问题讨论】: