Add nginx proxy for API endpoints - Contact form fully working
This commit is contained in:
@@ -20,6 +20,10 @@ services:
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./html:/usr/share/nginx/html:ro
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
networks:
|
||||
- default
|
||||
- mailcow-network
|
||||
|
||||
# 3. Contact Form Email Handler
|
||||
mail-contact:
|
||||
|
||||
@@ -75,10 +75,8 @@ if (contactSubmitBtn) {
|
||||
contactStatus.classList.add('hidden');
|
||||
|
||||
try {
|
||||
// Python FastAPI 엔드포인트로 요청
|
||||
// 현재 페이지의 호스트를 사용
|
||||
const apiUrl = `${window.location.protocol}//${window.location.hostname}:8001/api/contact`;
|
||||
const response = await fetch(apiUrl, {
|
||||
// FastAPI 엔드포인트로 요청 (nginx 프록시를 통함)
|
||||
const response = await fetch('/api/contact', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"cpu_temp": "42", "nvme_temp": "35", "uptime_days": 2, "last_update": "06:22:01"}
|
||||
{"cpu_temp": "43", "nvme_temp": "35", "uptime_days": 2, "last_update": "06:28:01"}
|
||||
28
nginx.conf
Normal file
28
nginx.conf
Normal file
@@ -0,0 +1,28 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name localhost;
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
# API 프록시
|
||||
location /api/ {
|
||||
proxy_pass http://hanmo-mail-contact:8001;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user