浏览器如果需要开发某些特定功能,需要https
浏览器才会给予功能权限, 则开发时我们需要在https环境
下面是配置一个webpack
devServer
的https
环境
//webpack.config.js
module.exports = {
...
devServer: {
port: 8080,
proxy: [{
context: ['/api'], //将 "https://urlname.com:8080/api" 转发到 "https://127.0.0.1:6495/api"
target: 'https://127.0.0.1:6495',
secure: false,
changeOrigin: true
}],
host: '0.0.0.0',
allowedHosts: [ 'urlname.com' ],
https: { //开启的端口可以通过https访问
key: fs.readFileSync('./cert/urlname.com.key'),
cert: fs.readFileSync('./ecrt/urlname.crt')
}
}
}