Grunt服务器如何正确设置主机名和虚拟主机?

时间:2014-07-14 10:46:49

标签: javascript angularjs gruntjs virtualhost hosts

我想在自定义域上的生产服务器上测试我的角度应用。

我试图这样做:

  • 我停用了Apache服务器
  • 我在/ etc / hosts 127.0.0.1:9000 mydomain.loc
  • 添加了一行
  • 我将配置更新为GruntFile.js

    //实际的grunt服务器设置

      connect: {
          options: {
            port: 9000,
            // Change this to '0.0.0.0' to access the server from outside.
            hostname: 'localhost',
            livereload: 35729
          },
          livereload: {
            options: {
              open: 'http://mydomain.loc:9000',
              base: [
                '.tmp',
                '<%= yeoman.app %>'
              ]
            }
          },
          test: {
            options: {
              port: 9001,
              base: [
                '.tmp',
                'test',
                '<%= yeoman.app %>'
              ]
            }
      },
    

在此之后我使用 grunt serve命令运行服务器。

初始化Grunt,在正确的地址mydomain.loc打开浏览器窗口:9000

但是在浏览器中找不到服务器。

问题是:

我做错了什么,我该如何解决?

我想,这不需要Apache吗?

感谢您的任何建议。

1 个答案:

答案 0 :(得分:1)

如本回答所述:Grunt server does not use virtual host name for my app..vhost and httpd are set up but grunt is not using them

hostname选项仅用于指定livereload应连接到的位置。这不会更改启动Grunt时打开的默认URL。您需要在livereload选项中指定打开的URL。例如:

livereload: {
    options: {
        open: 'http://myapp.dev:9000',
        base: [
            '.tmp',
            '<%= yeoman.app %>'
        ]
    }
}