繁体   English   中英

grunt-serve 不提供带有“/”请求的 index.html

[英]grunt-serve doesn't serve index.html with '/' request

我在让带有 grunt-serve 任务的本地服务器表现得像普通服务器一样时遇到问题。 我的grunt.initConfig对象如下:

  grunt.initConfig({
    'serve': {
      'path': '/Users/honkdonky/Desktop/testspace/angular',
      },
      'options': {
        'port': '9999'
      }
    }
  });

但是当我请求此链接时:

http://localhost:9999/

index.html 没有呈现。 相反,我看到的是可用文件列表。 该项目应该通过呈现 index.html 并按照 angularjs 模块中的配置路由来将请求路由到“/”。 其配置如下:

phoneApp.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/phones', {
                templateUrl: 'phone-list.html',
                controller: 'PhoneListCtrl'
            }).
            when('/phones/:phoneId', {
                templateUrl: 'phone-detail.html',
                controller: 'PhoneDetailCtrl'
            }).
            otherwise({
                redirectTo: '/phones'
            });
    }
]);

grunt-serve包用于运行任务提供文件,它不能渲染 / 到 index.html,如果你需要一个 web 服务器,你可以使用grunt-contrib-connect

我不知道这是否有帮助。 但我建议你可以尝试使用gulp-webserver 它使用起来非常简单,并且具有很酷的功能,例如 livereload(只要文件夹中有任何更改,就会自动刷新浏览器)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM