在使用geolocation API时,总是获取不到权限,发现只有在https环境下可以使用该api
- 参考别人的简书,只是简单的记录自己的操作,以便日后翻阅,并无延伸
- https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl
生成SSL证书
$ openssl req -x509 -newkey rsa:4096 -keyout gaarahan.key -out gaarahan.cert -days 365 -nodes
- 根据提示输入信息即可
- 先生成了一个
key
,存储在gaarahan.key,再根据刚才生成的key
,生成一个对应的证书gaarahan.cert
开启nodejs服务
const express = require('express');
const app = new express();
const https = require('https');
const fs = require('fs');
const path = require('path');
let options = {
key : fs.readFileSync('./ssl/gaarahan.key'),
cert: fs.readFileSync( './ssl/gaarahan.cert' ),
requestCert: false,
rejectUnauthorized: false
};
app.get('/',()=>{
console.log('got');
});
let server = https.createServer(options,app);
server.listen(8080,()=>{
console.log("listening http://localhost:8080/");
});
网友评论