首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"index.html“不是由grunt-contrib connect提供的

"index.html“不是由grunt-contrib connect提供的
EN

Stack Overflow用户
提问于 2014-12-31 13:28:34
回答 2查看 765关注 0票数 0

我的代码非常简单,grunt文件是,

代码语言:javascript
复制
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“。当我打开的时候

代码语言:javascript
复制
"http://localhost:8080"

它给出"Cannot GET /“。你知道为什么会发生这种事吗?

EN

回答 2

Stack Overflow用户

发布于 2015-02-19 20:29:31

对于如下所示的目录结构:

代码语言:javascript
复制
-node_modules
-templates
---index.html
---login.html
-Gruntfile.js

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

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

票数 1
EN

Stack Overflow用户

发布于 2015-02-19 21:36:56

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

代码语言:javascript
复制
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'
   ]);

};

而且必须工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27716569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档