set new path for proxy pass and location, with slash in the end of paths

This commit is contained in:
2025-10-06 02:48:10 +05:00
parent 85c7c9cfb7
commit 9065f34365
5 changed files with 19 additions and 14 deletions
+1
View File
@@ -97,5 +97,6 @@ networks:
web-network: web-network:
driver: bridge driver: bridge
internal: internal:
driver: bridge
app-network: app-network:
name: serv_golang_rest_api_app-network name: serv_golang_rest_api_app-network
+2 -2
View File
@@ -31,8 +31,8 @@ server {
} }
# New location for REST API # New location for REST API
location /api { location /api/ {
proxy_pass http://api:8080; proxy_pass http://api:8080/;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -4,8 +4,8 @@ package middleware
import ( import (
"context" "context"
"net/http" "net/http"
"strings"
"serv_golang_rest_api/internal/utils" "serv_golang_rest_api/internal/utils"
"strings"
) )
func AuthMiddleware(next http.Handler) http.Handler { func AuthMiddleware(next http.Handler) http.Handler {
@@ -2,6 +2,7 @@ package server
import ( import (
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"serv_golang_rest_api/internal/handlers" "serv_golang_rest_api/internal/handlers"
"serv_golang_rest_api/internal/middleware" "serv_golang_rest_api/internal/middleware"
@@ -37,9 +38,15 @@ func (s *Server) configureRouter(db *gorm.DB) {
// API routes // API routes
s.router.Route("/v1", func(r chi.Router) { s.router.Route("/v1", func(r chi.Router) {
s.router.Get("/check", s.healthCheck) r.Get("/check", s.healthCheck)
s.setupUserRoutes(r, db) s.setupUserRoutes(r, db)
}) })
// Для отладки - выводим все маршруты
chi.Walk(s.router, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
fmt.Printf("[%s] %s\n", method, route)
return nil
})
} }
func (s *Server) setupUserRoutes(r chi.Router, db *gorm.DB) { func (s *Server) setupUserRoutes(r chi.Router, db *gorm.DB) {
@@ -50,9 +57,6 @@ func (s *Server) setupUserRoutes(r chi.Router, db *gorm.DB) {
authHandler := &handlers.AuthHandler{DB: db} authHandler := &handlers.AuthHandler{DB: db}
oauthHandler := &handlers.OAuthHandler{DB: db} oauthHandler := &handlers.OAuthHandler{DB: db}
// Health check
r.Get("/health", s.healthCheck)
// Публичные маршруты // Публичные маршруты
r.Route("/auth", func(r chi.Router) { r.Route("/auth", func(r chi.Router) {
r.Post("/register", authHandler.Register) r.Post("/register", authHandler.Register)