【问题标题】:Planetscale post request error 'client must use SSL/TLS'Planetscale 发布请求错误\'客户端必须使用 SSL/TLS\'
【发布时间】:2022-10-06 09:30:33
【问题描述】:
使用工具
- Planetscale MySQL 云数据库
- 快递
- 招摇
- Heroku
我试图从邮递员和 swagger api doc 向服务器发送一个发布请求。
但我得到了这个错误。
unknown error: Code: UNAVAILABLE
server does not allow insecure connections, client must use SSL/TLS
使用 localhost 时我可以发送发布请求。但是在heroku上部署应用程序后,我不能再这样做了。
标签:
mysql
express
ssl
heroku
【解决方案1】:
在documentation 中解释如何加载certificates
const sequelize = new Sequelize({
dialect: 'mysql',
username: MYSQL_USER,
password: MYSQL_PASSWORD,
host: MYSQL_HOST,
dialectOptions: {
bigNumberStrings: true,
ssl: {
ca: fs.readFileSync(__dirname + '/ca-certificates.crt')
}
}
})
【解决方案2】:
更快的解决方案是:
const sequelize = new Sequelize(
"DATABASE_NAME",
"USERNAME",
"PASSWORD",
{
host: "HOST",
dialect: "mysql",
dialectOptions: {
ssl: {
rejectUnauthorized: true,
},
},
define: {
timestamps: false,
},
}
);
有了这个,我们不需要导入证书。