Ina*_*man 4 postgresql ssl node.js express sequelize.js
我正在尝试将我的项目与 PostgreSQL 连接,但显示此错误。请帮助我,我已经安装了 Postgres.app 和 GUI PgAdmin。
Unhandled rejection SequelizeConnectionError: The server does not support SSL connections
at /Users/inamur/Documents/Project/project-api/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:186:20
at Connection.connectingErrorHandler (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/client.js:203:14)
at Connection.emit (events.js:223:5)
at Connection.EventEmitter.emit (domain.js:475:20)
at Socket.<anonymous> (/Users/inamur/Documents/Project/project-api/node_modules/pg/lib/connection.js:90:21)
at Object.onceWrapper (events.js:313:26)
at Socket.emit (events.js:223:5)
at Socket.EventEmitter.emit (domain.js:475:20)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:181:23)
Run Code Online (Sandbox Code Playgroud)
这是我的 .env 文件
JWT_SECRET='UserNews'
DB_LINK='postgres://root:root@localhost:5432/SCROLL001?ssl=true'
Run Code Online (Sandbox Code Playgroud)
这是连接文件。
const sequelize = new Sequelize(process.env.DB_LINK, {
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: {
require: 'true'
}
}
});
Run Code Online (Sandbox Code Playgroud)
我已经解决了这个问题。
const sequelize = new Sequelize(process.env.DB_LINK, {
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {}, //removed ssl
});
Run Code Online (Sandbox Code Playgroud)
更改数据库链接
DB_LINK='postgres://root:root@localhost:5432/SCROLL001'
Run Code Online (Sandbox Code Playgroud)
建议在生产应用程序中使用 SSL 进行连接。您可以继续使用 SSL 连接,同时使用以下方法在本地规避它:
const sequelize = new Sequelize(process.env.DB_LINK, {
dialect: 'postgres',
protocol: 'postgres',
ssl: process.env.DB_ENABLE_SSL,
dialectOptions: {
ssl: process.env.DB_ENABLE_SSL && {
require: true
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4120 次 |
| 最近记录: |