Skip to content

Commit d3b676c

Browse files
committed
set up frontend + docker-compose
1 parent 2edff30 commit d3b676c

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

config/nginx/default.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Replace or edit config/nginx/default.conf with:
2+
server {
3+
listen 80;
4+
server_name localhost;
5+
6+
root /usr/share/nginx/html;
7+
index index.html;
8+
9+
# Handle local schemas
10+
location /schemas/ {
11+
alias /usr/share/nginx/html/schemas/;
12+
try_files $uri $uri/ =404;
13+
14+
# Enable CORS
15+
add_header 'Access-Control-Allow-Origin' '*';
16+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
17+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
18+
}
19+
20+
# Handle SPA routing
21+
location / {
22+
try_files $uri $uri/ /index.html;
23+
}
24+
}

config/nginx/prod.conf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
server {
2+
listen 80;
3+
server_name ${NGINX_HOST};
4+
# Redirect all HTTP to HTTPS
5+
return 301 https://$server_name$request_uri;
6+
}
7+
8+
server {
9+
listen 443 ssl;
10+
server_name ${NGINX_HOST};
11+
# SSL configuration
12+
ssl_certificate /etc/nginx/ssl/cert.pem;
13+
ssl_certificate_key /etc/nginx/ssl/key.pem;
14+
ssl_protocols TLSv1.2 TLSv1.3;
15+
ssl_ciphers HIGH:!aNULL:!MD5;
16+
17+
# Security headers
18+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
19+
add_header X-Frame-Options "SAMEORIGIN" always;
20+
add_header X-XSS-Protection "1; mode=block" always;
21+
add_header X-Content-Type-Options "nosniff" always;
22+
23+
# Frontend
24+
location / {
25+
proxy_pass http://frontend:3000;
26+
proxy_http_version 1.1;
27+
proxy_set_header Upgrade $http_upgrade;
28+
proxy_set_header Connection 'upgrade';
29+
proxy_set_header Host $host;
30+
proxy_cache_bypass $http_upgrade;
31+
32+
# Add SPA routing support
33+
try_files $uri $uri/ /index.html;
34+
}
35+
36+
# Backend API
37+
location /api/ {
38+
proxy_pass http://backend:8000/;
39+
proxy_http_version 1.1;
40+
proxy_set_header Upgrade $http_upgrade;
41+
proxy_set_header Connection 'upgrade';
42+
proxy_set_header Host $host;
43+
proxy_cache_bypass $http_upgrade;
44+
}
45+
46+
# Local schema files (when using LOCAL_SCHEMA_DIR)
47+
location /schema/ {
48+
alias /usr/share/nginx/html/schema/;
49+
50+
# Enhanced CORS configuration
51+
add_header 'Access-Control-Allow-Origin' '*';
52+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
53+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
54+
55+
# Handle OPTIONS preflight requests
56+
if ($request_method = 'OPTIONS') {
57+
add_header 'Access-Control-Allow-Origin' '*';
58+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
59+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
60+
add_header 'Access-Control-Max-Age' 1728000;
61+
add_header 'Content-Type' 'text/plain charset=UTF-8';
62+
add_header 'Content-Length' 0;
63+
return 204;
64+
}
65+
66+
autoindex on;
67+
expires -1;
68+
69+
# Ensure JSON files are served with correct content type
70+
types {
71+
application/json json;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)