Skip to content
Snippets Groups Projects
Commit e3bfa536 authored by Lukáš Kratochvíl's avatar Lukáš Kratochvíl
Browse files

Merge branch 'backend-setup' into main

parents 62c312e0 4637867d
No related branches found
No related tags found
No related merge requests found
# Node
node_modules/
# JetBrains IDEA # JetBrains IDEA
.idea/ .idea/
# .env files # .env files
.env .env
# Database
database-storage
# Database
database-storage
# compiled output # compiled output
/dist /dist
/node_modules /node_modules
......
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
@Module({ @Module({
imports: [ imports: [],
ConfigModule.forRoot({
envFilePath: '../.env',
}),
],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],
}) })
......
...@@ -5,8 +5,9 @@ import { AppModule } from './app.module'; ...@@ -5,8 +5,9 @@ import { AppModule } from './app.module';
async function bootstrap(): Promise<void> { async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
const configService = new ConfigService(); const configService = new ConfigService();
const port = configService.get('SERVER_PORT'); const port = configService.get('PORT');
console.log(`NestJS server is listening on: http://localhost:${port}`); console.log(`NestJS server is listening on: http://localhost:${port}`);
await app.listen(port); await app.listen(port);
} }
bootstrap(); bootstrap();
...@@ -8,16 +8,17 @@ services: ...@@ -8,16 +8,17 @@ services:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
command: npm run start:debug command: npm run start:debug
env_file: .env
ports: ports:
- 127.0.0.1:${SERVER_PORT}:${SERVER_PORT} - 127.0.0.1:${SERVER_PORT}:${SERVER_PORT}
networks:
- backend-network
volumes: volumes:
# changes in host's ./backend directory will be propagated to the container # changes in host's ./backend directory will be propagated to the container
- ./backend:/usr/src/app - ./backend:/usr/src/app
# this prevents our host files from overriding container's node_modules # this prevents our host files from overriding container's node_modules
- exclude-server:/usr/src/app/node_modules/ - exclude-server:/usr/src/app/node_modules/
networks: environment:
- backend-network - PORT=${SERVER_PORT}
restart: always restart: always
depends_on: depends_on:
- postgres - postgres
...@@ -25,11 +26,10 @@ services: ...@@ -25,11 +26,10 @@ services:
postgres: postgres:
container_name: postgres container_name: postgres
image: postgres:14.3-alpine image: postgres:14.3-alpine
env_file: .env
volumes:
- ./backend/database-storage:/var/lib/postgresql/data
networks: networks:
- backend-network - backend-network
volumes:
- ./backend/database-storage:/var/lib/postgresql/data
environment: environment:
POSTGRES_USER: ${DB_USER} POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_PASSWORD: ${DB_PASSWORD}
...@@ -39,7 +39,6 @@ services: ...@@ -39,7 +39,6 @@ services:
adminer: adminer:
container_name: adminer container_name: adminer
image: adminer:4.8.1 image: adminer:4.8.1
env_file: .env
ports: ports:
- 127.0.0.1:${ADMINER_PORT}:${ADMINER_PORT} - 127.0.0.1:${ADMINER_PORT}:${ADMINER_PORT}
networks: networks:
...@@ -53,14 +52,14 @@ services: ...@@ -53,14 +52,14 @@ services:
nginx: nginx:
container_name: nginx container_name: nginx
image: nginx:1.21.6-alpine image: nginx:1.21.6-alpine
env_file: .env
ports: ports:
- 127.0.0.1:${NGINX_PORT}:${NGINX_PORT} - 127.0.0.1:${NGINX_PORT}:${NGINX_PORT}
networks:
- backend-network
- frontend-network
volumes: volumes:
- ./nginx/templates:/etc/nginx/templates - ./nginx/templates:/etc/nginx/templates
- ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/nginx.conf:/etc/nginx/nginx.conf
networks:
- backend-network
environment: environment:
- NGINX_PORT=${NGINX_PORT} - NGINX_PORT=${NGINX_PORT}
- SERVER_PORT=${SERVER_PORT} - SERVER_PORT=${SERVER_PORT}
...@@ -75,20 +74,26 @@ services: ...@@ -75,20 +74,26 @@ services:
build: build:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile
env_file: .env
ports: ports:
- 127.0.0.1:${CLIENT_PORT}:${CLIENT_PORT} - 127.0.0.1:${CLIENT_PORT}:${CLIENT_PORT}
networks:
- frontend-network
volumes: volumes:
# changes in host's ./frontend directory will be propagated to the container # changes in host's ./frontend directory will be propagated to the container
- ./frontend:/usr/src/app - ./frontend:/usr/src/app
# this prevents our host files from overriding container's node_modules # this prevents our host files from overriding container's node_modules
- exclude-client:/usr/src/app/node_modules/ - exclude-client:/usr/src/app/node_modules/
environment:
- PORT=${CLIENT_PORT}
# all the traffic goes through Nginx server
- SERVER_PORT=${NGINX_PORT}
restart: always restart: always
networks:
backend-network:
frontend-network:
volumes: volumes:
database-storage: database-storage:
exclude-server: exclude-server:
exclude-client: exclude-client:
networks:
backend-network:
...@@ -2,16 +2,12 @@ import { defineConfig, loadEnv } from 'vite' ...@@ -2,16 +2,12 @@ import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default ({ mode }) => { export default defineConfig({
process.env = {...process.env, ...loadEnv(mode, `../${process.cwd()}`, '')}; plugins: [react()],
server: {
return defineConfig({ watch: {
plugins: [react()], usePolling: true
server: { },
watch: { port: +process.env.PORT
usePolling: true }
}, })
port: +process.env.CLIENT_PORT
}
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment