Skip to content

Commit

Permalink
feat: get user info from cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
D1mitrii committed Nov 12, 2024
1 parent 6a397c3 commit c3c7aa5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Run(cfg *config.Config) {

// route v1
r.Route("/v1", func(r chi.Router) {
// r.Use(middlewares.NewAuthMiddleware(jwt).JWT)
r.Use(middlewares.NewAuthMiddleware(jwt).JWT)
// TODO: Add v1 routes
r.Mount("/users", v1users.New(userService, addressService).Routes())
r.Mount("/services", v1services.New(service).Routes())
Expand Down
4 changes: 4 additions & 0 deletions backend/internal/controllers/http/v1/users/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/moevm/nosql2h24-cleaning/cleaning/internal/controllers/http/middlewares"
"github.com/moevm/nosql2h24-cleaning/cleaning/internal/models"
"github.com/moevm/nosql2h24-cleaning/cleaning/internal/services"
"github.com/moevm/nosql2h24-cleaning/cleaning/pkg/httputil"
Expand All @@ -25,6 +26,9 @@ import (
// @Router /api/v1/users/{id} [get]
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
if id == "me" {
id = r.Context().Value(middlewares.UserID).(string)
}
user, err := h.userService.GetUserById(r.Context(), id)
if err != nil {
if errors.Is(err, services.ErrUserNotFound) {
Expand Down
30 changes: 25 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
services:
frontend:
container_name: frontend
hostname: frontend
build:
context: frontend/
dockerfile: Dockerfile
ports:
- "127.0.0.1:8080:80"
expose:
- "80"
depends_on:
- backend
networks:
- proxy

backend:
container_name: backend
hostname: backend
build:
context: backend/
dockerfile: Dockerfile
ports:
- "127.0.0.1:8081:8081"
expose:
- "8081"
env_file:
- .env
depends_on:
db:
condition: service_healthy
networks:
- database
- proxy

proxy:
container_name: proxy
build:
context: proxy/
dockerfile: Dockerfile
ports:
- "8080:80"
depends_on:
- frontend
- backend
networks:
- proxy

db:
container_name: database
Expand Down Expand Up @@ -50,4 +69,5 @@ volumes:
mongo-data:

networks:
database:
database:
proxy:
5 changes: 5 additions & 0 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.27.2

COPY default.conf /etc/nginx/conf.d/default.conf

CMD [ "nginx", "-g", "daemon off;" ]
22 changes: 22 additions & 0 deletions proxy/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;
listen [::]:80;

server_name localhost;

location / {
proxy_pass http://frontend:80;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}

location /api {
proxy_pass http://backend:8081;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}

0 comments on commit c3c7aa5

Please sign in to comment.