app still wont connect to database...

This commit is contained in:
slawk0
2024-08-25 22:42:59 +02:00
parent 94e0156c89
commit 12ad8a5b99
4 changed files with 48 additions and 22 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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}
user: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_HOST=${PG_HOST}
- POSTGRES_DB=${PG_DATABASE}
- POSTGRES_PASSWORD=${PG_PASSWORD}
POSTGRES_USER: postgres
POSTGRES_DB: webchat
POSTGRES_PASSWORD: jebanechaslo
expose:
- ${PG_PORT}:5432
- "5432"
healthcheck:
test: [ "CMD", "pg_isready" ]
test: ["CMD", "pg_isready", "-U", "${PG_USER}"]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data: