2016-04-28 84 views
2

我有一个问题,让grunt-serve任务的本地服务器的行为应该像普通服务器一样。我grunt.initConfig对象就像如下:grunt-serve不为'index.html'提供'/'请求

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' 
      }); 
    } 
]); 

回答

0

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

+1

将gulp添加到工具列表中并不是一个好选择,但您的主要想法是正确的; grunt-serve并不是作为服务器的最佳选择。 –