0

我的代码很简单,而 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"

它给出“无法获取 /”。知道为什么会这样吗?

4

2 回答 2

1

对于如下目录结构:

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

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

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

于 2015-02-19T12:29:30.950 回答
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'
   ]);

};

并且必须工作。

于 2015-02-19T13:36:55.823 回答