"的index.html"没有grunt-contrib-connect服务

时间:2014-12-31 05:28:34

标签: javascript gruntjs grunt-contrib-connect

我的代码很简单,而grunt文件是

module.exports = function(grunt) {

   var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

   grunt.initConfig({
      connect: {
         server: {
            options: {
               hostname: "localhost",
               keepalive: true,
               base:['../web/'],
               port: 8080,
               middleware: function(connect, options) {
                  return [proxySnippet];
               },
               debug: true
            }
         }
      }
   });

   // grunt.loadNpmTasks('grunt-connect-proxy');
   grunt.loadNpmTasks('grunt-contrib-connect');

   grunt.registerTask('default', [

      'connect:server'
   ]);

};

有一个index.html,路径为“../web/index.html”。当我打开

"http://localhost:8080"

它给出了“不能GET /”。知道为什么会这样吗?

2 个答案:

答案 0 :(得分:1)

对于如下目录结构:

-node_modules
-templates
---index.html
---login.html
-Gruntfile.js

connect: {
         options: {
                port: 9000,
                livereload: true,
                hostname: 'localhost',
         },
         livereload: {
              options: {
                    open: true,
                    base: ['templates/']
              }
         }
    }

这将在浏览器上打开 templates 的完整目录结构,以导航到任何html页面。

答案 1 :(得分:0)

删除中间件代理,如下所示:

module.exports = function(grunt) {

   var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

   grunt.initConfig({
      connect: {
         server: {
            options: {
               hostname: "localhost",
               keepalive: true,
               base:['../web/'],
               port: 8081,

               debug: true
            }
         }
      }
   });

   // grunt.loadNpmTasks('grunt-connect-proxy');
   grunt.loadNpmTasks('grunt-contrib-connect');

   grunt.registerTask('default', [

      'connect:server'
   ]);

};

必须工作。