簡體   English   中英

403從本地主機提供資源

[英]403 serving resources from localhost

我剛剛安裝了Nodejs和Grunt,主要用於在模擬不同的UI想法時使用Grunt的livereload。 不用擔心啟動服務器並查看index.html,但是所有CSS和JS資源都會收到403錯誤。

每當我啟動/交付服務器時,也會看到以下錯誤。 任何建議都很棒。

錯誤:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM