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

标签 javascript angularjs gruntjs virtualhost hosts

我想在自定义域的生产服务器上测试我的 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 吗?

感谢您的任何建议。

最佳答案

如本回答所述: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 %>'
        ]
    }
}

关于javascript - Grunt 服务器如何正确设置主机名和虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734812/

相关文章:

javascript - jQuery 中的并行异步请求

javascript - 从 angularjs 调用 REST 服务时本地主机上的 CORS 问题

javascript - gruntjs 和 livereload 到已经运行的本地主机

javascript - Grunt 不观察 JS 文件

javascript - grunt-spritesmith 配置在 gruntfile.js 上无法正常工作

javascript - JQuery 未在 Cordova 中执行

javascript - Turbolinks 与 Adsense 异步广告代码

javascript - slider 图像需要一些时间来加载。

javascript - AngularJS 实现检查所有输入作为可重用指令的最佳方法

javascript - AngularJS 在 $scope 数组上使用 ng-repeat