【问题标题】:How remove port number ":80" when serving localhost using grunt-contrib-connect使用 grunt-contrib-connect 服务本地主机时如何删除端口号“:80”
【发布时间】:2019-11-22 08:32:24
【问题描述】:

当我使用 grunt-contrib-connect 为我的项目提供服务时,我需要它使用 https 运行,并且在浏览器中的根路径需要是: https://localhost/

我不熟悉如何使用 grunt-contrib-connect 中的代理选项进行设置。

我的 grunt.initConfig 设置是:

connect: {
            server: {
              options: {
                port: 80,
                base: 'dist',
                protocol: 'https',
                livereload: true,
                keepalive: true,
                debug: true,
                hostname: 'localhost',
                open: true
              }
            }
        },
    ```

This serves the project to https://localhost:80/

I will finish setting up livereload once this is working correctly.

Thanks for your help.

【问题讨论】:

    标签: grunt-contrib-connect


    【解决方案1】:

    对于地址栏中没有端口号的 https,需要将端口设置为 443,对于 livereload,您必须创建简单的、自行生成的证书 - 它们可以驻留在项目文件夹中,因为它们没有任何连接安全。

    我的 gruntfile 中的连接/监视设置是:

    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-watch');
    
        // Project configuration.
        grunt.initConfig({
            //live server
            connect: {
                server: {
                  options: {
                    port: 443,
                    base: 'dist', //the folder my compiled web files are generated in
                    protocol: 'https',
                    livereload: true,
                    debug: true, //show me what is being served, helpful for debugging
                    hostname: 'localhost',
                    open: true //auto-open browser tab - remove if annoying
                  }
                }
            },
    
            //watch for changes and recompile / reload
            watch: {
                dev: {
                    options: {
                        livereload: {
                            port: 35729,
                            key: grunt.file.read('livereload.key'),
                            cert: grunt.file.read('livereload.crt')
                            // you can pass in any other options you'd like to the https server, as listed here: http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
                        }
                    },
                    files: [   // Files to livereload on
                        "js/**/*.*",
                        "less/admin/*.less",
                        "./*.html",
                        "./Gruntfile.js",
                        "snippets/*.*"
                    ],
                    tasks: [
                        'dev' //the task to run after a change is detected
                    ]
                }
            },
    .....
    

    本指南帮助我创建了证书: https://www.gilluminate.com/2014/06/10/livereload-ssl-https-grunt-watch/

    :9000 详细信息对我不起作用,我将 livereload 端口保留在 35729,一旦服务器启动并运行,在新选项卡中点击它以授权使用自行生成的证书访问脚本: https://localhost:35729/livereload.js?snipver=1

    我希望这对某人有所帮助;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-12
      • 2014-07-28
      • 2015-01-25
      • 1970-01-01
      • 2014-11-19
      • 2022-12-30
      • 2013-11-14
      • 2019-01-08
      相关资源
      最近更新 更多