Skip to content
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
39 changes: 21 additions & 18 deletions cmd/api-gateway/main.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package main

import (
"EventSpace/internal/server"
"log"
"os"

"github.com/pelletier/go-toml/v2"
"net/http"
"net/http/httputil"
"net/url"
"strings"
)

func main() {

doc, err := os.ReadFile("config/api-gateway/config.toml")

if err != nil {
log.Fatalf("Error to load api-gateway config: %v", err)
proxies := map[string]*httputil.ReverseProxy{
"/v1/auth/": httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http",
Host: "auth-service:8081"}),
}

var config server.Config
err = toml.Unmarshal(doc, &config)

if err != nil {
log.Fatalf("Error to parse api-gateway config: %v", err)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
for prefix, proxy := range proxies {
if strings.HasPrefix(r.URL.Path, prefix) {
log.Printf("Proxy %s\n", r.URL.Path)
proxy.ServeHTTP(w, r)
return
}
}
log.Printf("No found url: %s\n", r.URL.Path)
http.NotFound(w, r)
})

if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err.Error())
}

server := server.NewServer(&config)

if err = server.Start(); err != nil {
log.Fatalf("Error to start api-gateway: %v", err)
}
}
6 changes: 3 additions & 3 deletions cmd/auth-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func main() {

authHandler := handler.NewAuthHandler(authService)

router.Post("/register", authHandler.RegisterHandler)
router.Post("/v1/auth/register", authHandler.RegisterHandler)

router.Post("/login", authHandler.Login)
router.Post("/v1/auth/login", authHandler.Login)

router.Post("/refresh", authHandler.Refresh)
router.Post("/v1/auth/refresh", authHandler.Refresh)

server := http.Server{
Addr: ":8081",
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ services:
auth-service:
build:
dockerfile: docker/auth-service/Dockerfile
ports:
- "8081:8081"
environment:
JWT_SECRET: ${JWT_SECRET}
DB_ADDR: ${DB_ADDR}
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/handler/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (h *AuthHandler) setRefreshTokenCookie(w http.ResponseWriter, refreshToken
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteStrictMode,
Path: "/refresh",
Path: "/",
MaxAge: 7 * 24 * 3600,
})
}
Loading