【问题标题】:Grunt server how to set hostname and virtual host correctly?Grunt 服务器如何正确设置主机名和虚拟主机?
【发布时间】:2014-09-04 06:25:49
【问题描述】:

我想在自定义域的生产服务器上测试我的 Angular 应用程序。

我尝试过这样做:

  • 我停用了 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?

感谢您的任何建议。

【问题讨论】:

标签: javascript angularjs gruntjs virtualhost hosts


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-02-08
    • 2021-04-17
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2020-04-14
    • 2014-07-06
    相关资源
    最近更新 更多