add support for reading database url from password
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -11,7 +12,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
errDB := database.InitDB(os.Getenv("DATABASE_URL"))
|
databaseUrl := os.Getenv("DATABASE_URL")
|
||||||
|
if databaseUrl == "" {
|
||||||
|
content, err := ioutil.ReadFile(os.Getenv("DATABASE_URL_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
databaseUrl = string(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
errDB := database.InitDB(databaseUrl)
|
||||||
if errDB != nil {
|
if errDB != nil {
|
||||||
log.Fatalf("⛔ Unable to connect to database: %v\n", errDB)
|
log.Fatalf("⛔ Unable to connect to database: %v\n", errDB)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const { Pool } = require('pg');
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
databaseUrl =
|
||||||
|
process.env.DATABASE_URL ||
|
||||||
|
fs.readFileSync(process.env.DATABASE_URL_FILE, 'utf8');
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: process.env.DATABASE_URL,
|
connectionString: databaseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
// the pool will emit an error on behalf of any idle clients
|
// the pool will emit an error on behalf of any idle clients
|
||||||
|
|||||||
Reference in New Issue
Block a user