我遵循一個指南,即如何在PostgreSQL上創建一個Node JS后端和一個ReactJS前端,效果很好,更多內容請見這里。
。quide的js池物件看起來如下:
const Pool = require('pg')。 Pool。
const pool = new Pool({
user: 'my_user',
host: 'localhost',
database: 'my_database',
password: 'postgres',
port: 5432。
});
我試著用一個使用SSL加密的PostgreSQL Webserver做同樣的事情。這個問題沒有被標記為postgresql,因為這個池子在mysql和其他資料庫中看起來是一樣的。它也沒有被標記為Linux,因為它在其他作業系統上應該是一樣的。
如何在javascript中從Pool類中創建一個可以使用SSL連接到PostgreSQL后端的池物件?
CodePudding
你需要保存證書,稱之為server-certificate.pem,放在一個以/開始的靜態路徑的地方(~代表你的用戶的主目錄不起作用)。因此,你需要把它移到一個靜態的地方。
我把檔案復制到了一個靜態的地方。
我把檔案復制到一個新創建的目錄certificates,但這當然由你決定。你將需要超級用戶權限來完成這個任務。
/etc/certificates/server-certificate.pem
您需要加載fs并在SSL部分使用它,請參閱如何從Node.js API到AWS RDS建立安全連接(SSL)。
const Pool = require('pg')。 Pool。
const fs = require('fs')。
const pool = new Pool( {
user: 'my_user',
host: 'my_host',
database: 'my_database',
password: 'my_password',
port: 22222,
ssl: {
ca: fs
.readFileSync("/etc/certificates/server-certificate.pem")
.toString()
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/317198.html
標籤:
