app still wont connect to database...
This commit is contained in:
@@ -31,6 +31,8 @@ USER node
|
||||
# Copy the rest of the source files into the image.
|
||||
COPY . .
|
||||
|
||||
CMD npm i
|
||||
|
||||
# Expose the port that the application listens on.
|
||||
EXPOSE 3000
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const db = new Client({
|
||||
});
|
||||
|
||||
// create connection to database
|
||||
db .connect()
|
||||
db.connect()
|
||||
.then(() => console.log('Successfully connected to database'))
|
||||
.catch((err) => console.log('Error on connecting to database: ', err));
|
||||
|
||||
|
||||
@@ -4,6 +4,28 @@ const jwtSecret = process.env.JWT_SECRET;
|
||||
const { db } = require('./db.js');
|
||||
|
||||
function initializeSocket(server) {
|
||||
async function createTables() {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
)
|
||||
`);
|
||||
|
||||
// Create messages table
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
content TEXT NOT NULL,
|
||||
username VARCHAR(255) NOT NULL,
|
||||
recipient VARCHAR(255) NOT NULL,
|
||||
)
|
||||
`);
|
||||
|
||||
}
|
||||
|
||||
const io = new Server(server, {
|
||||
cookie: {
|
||||
httpOnly: true,
|
||||
|
||||
44
compose.yaml
44
compose.yaml
@@ -1,3 +1,5 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web-chat:
|
||||
build:
|
||||
@@ -5,27 +7,27 @@ services:
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
ports:
|
||||
- 3000:3000
|
||||
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
- db
|
||||
|
||||
db:
|
||||
image: postgres:latest
|
||||
restart: always
|
||||
user: ${PG_USER}
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_HOST=${PG_HOST}
|
||||
- POSTGRES_DB=${PG_DATABASE}
|
||||
- POSTGRES_PASSWORD=${PG_PASSWORD}
|
||||
expose:
|
||||
- ${PG_PORT}:5432
|
||||
healthcheck:
|
||||
test: [ "CMD", "pg_isready" ]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
image: postgres:latest
|
||||
restart: always
|
||||
user: postgres
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_DB: webchat
|
||||
POSTGRES_PASSWORD: jebanechaslo
|
||||
expose:
|
||||
- "5432"
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "${PG_USER}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
db-data:
|
||||
|
||||
Reference in New Issue
Block a user