简体   繁体   English

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

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

I have a problem getting a local server with grunt-serve task to behave like a normal server should.我在让带有 grunt-serve 任务的本地服务器表现得像普通服务器一样时遇到问题。 My grunt.initConfig object is like follows:我的grunt.initConfig对象如下:

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

but when I request this link:但是当我请求此链接时:

http://localhost:9999/ http://localhost:9999/

index.html there is not rendered. index.html 没有呈现。 Instead what I see is a list of available files.相反,我看到的是可用文件列表。 The project should route requests to '/' by rendering index.html and routing as configured in angularjs module.该项目应该通过呈现 index.html 并按照 angularjs 模块中的配置路由来将请求路由到“/”。 Configuration of which is as follows:其配置如下:

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

I don't know if this could help.我不知道这是否有帮助。 But I suggest you could try using gulp-webserver .但我建议你可以尝试使用gulp-webserver It's pretty much easier to use and have a cool features such as livereload (automatically refresh the browser whenever there's any changes in the folder).它使用起来非常简单,并且具有很酷的功能,例如 livereload(只要文件夹中有任何更改,就会自动刷新浏览器)。

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

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