当我使用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.发布于 2019-11-26 16:09:23
对于地址栏中没有端口号的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
我希望这对某些人有帮助;)
https://stackoverflow.com/questions/58990320
复制相似问题