我刚刚安装了Nodejs和Grunt,主要是为了在模拟不同的UI想法时使用Grunt的livereload。无需担心启动服务器并查看index.html,但获取所有css和js资源的403错误。
每当我启动/ livereload服务器时,也会看到下面的错误。任何建议都很棒。
错误:
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'
]);
};
答案 0 :(得分:5)
在express
config(gruntfile.js)中将bases
更改为[__dirname]