Skip to content

Commit 99bbbc3

Browse files
committed
nginx
1 parent 9748a7a commit 99bbbc3

File tree

3 files changed

+47
-65
lines changed

3 files changed

+47
-65
lines changed

docker-compose.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ services:
2222
ports:
2323
- "80:80"
2424
volumes:
25-
- ./frontend/dist:/var/www/html
25+
- ./frontend/public:/var/www/html
2626
- ./media:/var/www/media
2727
depends_on:
2828
- django-dev
29+
- frontend-dev
2930
networks:
3031
- app_network
31-
extra_hosts:
32-
- "host.docker.internal:host-gateway"
3332

3433
django:
3534
image: ghcr.io/${OWNER_LC}/tibiknini:latest
@@ -201,8 +200,6 @@ services:
201200
- DOMAIN_NAME=nginx-dev
202201
networks:
203202
- app_network
204-
depends_on:
205-
- nginx-dev
206203

207204
redis:
208205
image: redis:7-alpine

frontend/app/old-app/components/BlogPostDetail.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import UserContext from "./contexts/UserContext";
2121
import {REDIRECT_REASONS} from "./constants/Constants";
2222
import BlogPostComments from "./BlogPostComments";
2323
import api from "../utils/api";
24+
import { getApiUrl } from "../../env.server";
2425

2526
const BlogPostDetail = ({ post }) => {
2627
const navigate = useNavigate();
@@ -73,9 +74,19 @@ const BlogPostDetail = ({ post }) => {
7374
}
7475

7576
try {
76-
const response = await api.post(`/blog/posts/id/${post.id}/like/`);
77-
setLikesCount(response.data.likes_count);
78-
setIsLiked(response.data.is_liked);
77+
const apiUrl = getApiUrl();
78+
const response = await fetch(`${apiUrl}/api/blog/posts/id/${post.id}/like/`, {
79+
method: 'POST',
80+
credentials: 'include'
81+
});
82+
83+
if (!response.ok) {
84+
throw new Error('Failed to like post');
85+
}
86+
87+
const data = await response.json();
88+
setLikesCount(data.likes_count);
89+
setIsLiked(data.is_liked);
7990
} catch (error) {
8091
console.error('Error liking post:', error);
8192
toast.error('Failed to like post');
@@ -153,4 +164,4 @@ const BlogPostDetail = ({ post }) => {
153164
);
154165
};
155166

156-
export default BlogPostDetail;
167+
export default BlogPostDetail;

nginx/nginx.conf.dev

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
server {
22
server_name localhost 89.111.174.61;
3+
listen 80;
34

4-
location /django-static/ {
5-
alias /var/www/staticfiles/;
5+
# Static files from public directory
6+
location /build/ {
7+
alias /var/www/html/build/;
8+
add_header Cache-Control "public, max-age=31536000, immutable";
69
}
710

8-
location /static/ {
9-
alias /var/www/html/static/;
11+
# Other static files (favicon, manifest, etc)
12+
location ~* \.(ico|png|json|txt)$ {
13+
root /var/www/html;
14+
try_files $uri =404;
15+
add_header Cache-Control "public, max-age=31536000";
1016
}
1117

12-
# Serve the main index.html file for the ReactJS frontend
13-
location / {
14-
root /var/www/html;
15-
try_files $uri /index.html;
18+
location /django-static/ {
19+
alias /var/www/staticfiles/;
1620
}
1721

1822
location /admin/ {
19-
proxy_pass http://django-dev:8000;
20-
proxy_set_header Host $host;
21-
proxy_set_header X-Real-IP $remote_addr;
22-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23-
proxy_set_header X-Forwarded-Proto $scheme;
23+
proxy_pass http://django-dev:8000;
24+
proxy_set_header Host $host;
25+
proxy_set_header X-Real-IP $remote_addr;
26+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27+
proxy_set_header X-Forwarded-Proto $scheme;
2428
}
2529

2630
location /api/ {
@@ -43,53 +47,23 @@ server {
4347
proxy_set_header X-Forwarded-Proto $scheme;
4448
}
4549

46-
# Vite dev server proxy
47-
location /ws {
48-
proxy_pass http://host.docker.internal:5173;
49-
proxy_http_version 1.1;
50-
proxy_set_header Upgrade $http_upgrade;
51-
proxy_set_header Connection "Upgrade";
52-
proxy_set_header Host $host;
53-
proxy_cache_bypass $http_upgrade;
54-
}
55-
56-
# Serve static files from Vite
57-
location /@fs/ {
58-
proxy_pass http://host.docker.internal:5173;
59-
proxy_http_version 1.1;
60-
proxy_set_header Host $host;
61-
proxy_cache_bypass $http_upgrade;
62-
}
63-
64-
location /@vite/ {
65-
proxy_pass http://host.docker.internal:5173;
66-
proxy_http_version 1.1;
67-
proxy_set_header Host $host;
68-
proxy_cache_bypass $http_upgrade;
69-
}
70-
71-
location /node_modules/ {
72-
proxy_pass http://host.docker.internal:5173;
73-
proxy_http_version 1.1;
74-
proxy_set_header Host $host;
75-
proxy_cache_bypass $http_upgrade;
50+
location /media/ {
51+
alias /var/www/media/;
7652
}
7753

78-
location /src/ {
79-
proxy_pass http://host.docker.internal:5173;
54+
# All other requests go to Remix
55+
location / {
56+
proxy_pass http://frontend-dev:3000;
8057
proxy_http_version 1.1;
58+
proxy_set_header Upgrade $http_upgrade;
59+
proxy_set_header Connection 'upgrade';
8160
proxy_set_header Host $host;
61+
proxy_set_header X-Real-IP $remote_addr;
62+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
63+
proxy_set_header X-Forwarded-Proto $scheme;
8264
proxy_cache_bypass $http_upgrade;
65+
66+
# Prevent redirect loops
67+
proxy_redirect off;
8368
}
84-
85-
location /media/ {
86-
alias /var/www/media/;
87-
}
88-
}
89-
90-
server {
91-
server_name localhost;
92-
93-
listen 80;
94-
return 301 https://$host$request_uri;
9569
}

0 commit comments

Comments
 (0)