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 the rest of the source files into the image.
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
CMD npm i
|
||||||
|
|
||||||
# Expose the port that the application listens on.
|
# Expose the port that the application listens on.
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const db = new Client({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// create connection to database
|
// create connection to database
|
||||||
db .connect()
|
db.connect()
|
||||||
.then(() => console.log('Successfully connected to database'))
|
.then(() => console.log('Successfully connected to database'))
|
||||||
.catch((err) => console.log('Error on connecting to database: ', err));
|
.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');
|
const { db } = require('./db.js');
|
||||||
|
|
||||||
function initializeSocket(server) {
|
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, {
|
const io = new Server(server, {
|
||||||
cookie: {
|
cookie: {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
|
|||||||
44
compose.yaml
44
compose.yaml
@@ -1,3 +1,5 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
web-chat:
|
web-chat:
|
||||||
build:
|
build:
|
||||||
@@ -5,27 +7,27 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- "3000:3000"
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
- db
|
||||||
condition: service_healthy
|
|
||||||
db:
|
db:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
restart: always
|
restart: always
|
||||||
user: ${PG_USER}
|
user: postgres
|
||||||
volumes:
|
volumes:
|
||||||
- db-data:/var/lib/postgresql/data
|
- db-data:/var/lib/postgresql/data
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_HOST=${PG_HOST}
|
POSTGRES_USER: postgres
|
||||||
- POSTGRES_DB=${PG_DATABASE}
|
POSTGRES_DB: webchat
|
||||||
- POSTGRES_PASSWORD=${PG_PASSWORD}
|
POSTGRES_PASSWORD: jebanechaslo
|
||||||
expose:
|
expose:
|
||||||
- ${PG_PORT}:5432
|
- "5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "pg_isready" ]
|
test: ["CMD", "pg_isready", "-U", "${PG_USER}"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db-data:
|
db-data:
|
||||||
|
|||||||
Reference in New Issue
Block a user