Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use docker compose for routing in docker compose #1

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
use docker compose for routing in docker compose
  • Loading branch information
naborisk committed Feb 13, 2024
commit 71350465390aa50936c4ceb40435074f1e9e3247
24 changes: 15 additions & 9 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: '3.8'
services:
frontend:
build: ./frontend
ports:
- '3000:3000'
# ports:
# - '3000:3000'
backend:
build: ./backend
ports:
- '3001:3001'
# ports:
# - '3001:3001'
restart: always
depends_on:
- db
Expand All @@ -16,12 +16,18 @@ services:
- 'DB_HOST=db'
db:
image: postgres
ports:
- '5432:5432'
# ports:
# - '5432:5432'
environment:
- 'POSTGRES_PASSWORD=postgres'
- 'POSTGRES_DB=todo'
adminer:
image: adminer
nginx:
image: nginx
ports:
- '8080:8080'
- '80:80'
# depends_on:
# - frontend
# - backend
restart: always
volumes:
- ./nginx/:/etc/nginx/conf.d/:ro
4 changes: 2 additions & 2 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Home() {
}, [])

const addTodo = () => {
fetch('http://localhost:3001/todos', {
fetch('/api/todos', {
method: 'POST',
body: JSON.stringify({
title,
Expand All @@ -57,7 +57,7 @@ export default function Home() {
}

const deleteTodo = (id: number) => {
fetch(`http://localhost:3001/todos/${id}`, {
fetch(`api/todos/${id}`, {
method: 'DELETE'
}).then(() => {
setData(data.filter(todo => todo.id !== id))
Expand Down
Binary file modified frontend/bun.lockb
Binary file not shown.
12 changes: 12 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 80;
server_name localhost;

location / {
proxy_pass http://frontend:3000/;
}

location /api/ {
proxy_pass http://backend:3001/;
}
}