2

I've just installed Nodejs and Grunt, mainly for using Grunt's livereload when mocking up different UI ideas. No worries starting the server and viewing index.html, but get 403 errors for all css and js resources.

Also seeing the error below whenever I start/livereload the server. Any advice would be awesome.

Error:

D:\Grunt>grunt server
Running "express:all" (express) task

Running "express-server:all" (express-server) task
Web server started on port:9000, hostname: 0.0.0.0 [pid: 3624]

Running "open:all" (open) task

Running "watch" task
Waiting...Error: Forbidden
    at SendStream.error (D:\Grunt\node_modules\grunt-express\node_modules\connec
t\node_modules\send\lib\send.js:145:16)
    at SendStream.pipe (D:\Grunt\node_modules\grunt-express\node_modules\connect
\node_modules\send\lib\send.js:310:52)
    at Object.static (D:\Grunt\node_modules\grunt-express\node_modules\connect\l
ib\middleware\static.js:84:8)
    at next (D:\Grunt\node_modules\grunt-express\node_modules\connect\lib\proto.
js:190:15)
    at Object.handle (D:\Grunt\node_modules\grunt-express\node_modules\connect-l
ivereload\index.js:53:14)
    at next (D:\Grunt\node_modules\grunt-express\node_modules\connect\lib\proto.
js:190:15)
    at Function.app.handle (D:\Grunt\node_modules\grunt-express\node_modules\con
nect\lib\proto.js:198:3)
    at Server.app (D:\Grunt\node_modules\grunt-express\node_modules\connect\lib\
connect.js:65:37)
    at Server.EventEmitter.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)
OK

Package.json:

{
  "name": "Example",
  "version": "0.0.1",
  "private": true,
  "devDependencies": {
    "grunt": "latest",
    "matchdep": "~0.1.2",
    "grunt-express": "~1.0.0-beta2",
    "grunt-contrib-watch": "~0.5.1",
    "grunt-open": "~0.2.1",
    "grunt-contrib-uglify": "latest",
    "grunt-contrib-jshint": "latest"
  }
}

gruntfile.js:

module.exports = function (grunt) {

    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

    grunt.initConfig({

        express: {
            all: {
                options: {
                    port: 9000,
                    hostname: "0.0.0.0",
                    bases: ['.'],
                    livereload: true
                }
            }
        },

        watch: {
            livereload: {
                options: {
                    livereload: true
                },
                files: ['*.*']
            }
        },

        jshint: {
            files: ['*.js']
        },

        open: {
            all: {
                path: 'http://localhost:<%= express.all.options.port%>'
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-jshint');

    grunt.registerTask('server', [
      'express',
      'open',
      'watch'
    ]);
};
4

1 回答 1

5

express配置(gruntfile.js)中更改bases[__dirname]

于 2013-11-29T22:18:41.177 回答