使用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']);

};


而且我不知道我的咕unt声文件代码是对还是错
其实是新手,我不知道该怎么办,正在运行手声时出现无法获取/此错误。

最佳答案

您只在Grunt中运行的连接服务器的设置中出现错误:

connect().use('/', serveStatic('/views'))


应该

connect().use('/', serveStatic('./server/views'))

09-18 11:39