首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用grunt-contrib-connect为localhost提供服务时删除端口号":80“

如何在使用grunt-contrib-connect为localhost提供服务时删除端口号":80“
EN

Stack Overflow用户
提问于 2019-11-22 16:32:24
回答 1查看 93关注 0票数 0

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

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

我的grunt.initConfig设置是:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2019-11-26 16:09:23

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

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

代码语言:javascript
复制
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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58990320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档