Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
9 changes: 6 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ FRONTEND_PORT=3000
BASE_URI=

## Question service variables
QUESTION_SVC_PORT=
QUESTION_SVC_PORT=8000
QUESTION_SVC_DB_URI=

## User service variables
USER_SVC_PORT=
USER_SVC_PORT=3001
USER_SVC_DB_URI=
JWT_SECRET=
EMAIL_ADDRESS=
Expand All @@ -26,4 +26,7 @@ MATCHING_SVC_PORT=6969
REDIS_PORT=6379

## Redisinsight variables
REDIS_INSIGHT_PORT=5540
REDIS_INSIGHT_PORT=5540

## API Gateway variables
API_GATEWAY_PORT=
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /admin/matching-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
location /admin/question-service/ {
location /admin/question-service/questions {
proxy_pass http://question-service/questions;
}
}
15 changes: 15 additions & 0 deletions api-gateway/templates/api_conf.d/api_backends.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
upstream user-service {
server user-service:$USER_SVC_PORT;
}

upstream question-service {
server question-service:$QUESTION_SVC_PORT;
}

upstream matching-service {
server matching-service:$MATCHING_SVC_PORT;
}

upstream frontend {
server frontend:$FRONTEND_PORT;
}
23 changes: 23 additions & 0 deletions api-gateway/templates/api_conf.d/auth.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
location /verify-token {
internal;

proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass http://user-service/auth/verify-token;
}

location /verify-owner {
internal;

proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass http://user-service/auth/verify-owner;
}

location /verify-admin {
internal;

proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass http://user-service/auth/verify-admin;
}
3 changes: 3 additions & 0 deletions api-gateway/templates/api_conf.d/frontend.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
location / {
proxy_pass http://frontend;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /owner/matching-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /owner/question-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
location /private/matching-service/ {
location /private/matching-service/match {
proxy_pass http://matching-service/match;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /private/question-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /private/user-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
location /public/matching-service/ {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
location /public/question-service/ {
location /public/question-service/questions {
limit_except GET {
deny all;
}
proxy_pass http://question-service/questions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
location /public/user-service/ {
location /public/user-service/auth {
proxy_pass http://user-service/auth;
}

location /public/user-service/users {
proxy_pass http://user-service/users;
}
}
31 changes: 31 additions & 0 deletions api-gateway/templates/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include conf.d/api_conf.d/api_backends.conf;

server {
listen $PORT;
listen [::]:$PORT;

location /public/ {
include conf.d/api_conf.d/public_conf.d/*.conf;
}

location /private/ {
auth_request /verify-token;
include conf.d/api_conf.d/private_conf.d/*.conf;
}

location /owner/ {
auth_request /verify-owner;
include conf.d/api_conf.d/owner_conf.d/*.conf;
}

location /admin/ {
auth_request /verify-admin;
include conf.d/api_conf.d/admin_conf.d/*.conf;
}

include conf.d/api_conf.d/auth.conf;

include conf.d/api_conf.d/frontend.conf;
}

include conf.d/map_conf.d/*.conf;
35 changes: 20 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@ services:
context: ./frontend
args:
- BASE_URI=$BASE_URI
- USER_SVC_PORT=$USER_SVC_PORT
- QUESTION_SVC_PORT=$QUESTION_SVC_PORT
- MATCHING_SVC_PORT=$MATCHING_SVC_PORT
ports:
- $FRONTEND_PORT:$FRONTEND_PORT
depends_on:
- question-service
- user-service
- API_GATEWAY_PORT=$API_GATEWAY_PORT
environment:
- PORT=$FRONTEND_PORT

question-service:
build:
context: ./question-service
ports:
- $QUESTION_SVC_PORT:$QUESTION_SVC_PORT
environment:
- PORT=$QUESTION_SVC_PORT
- DB_URI=$QUESTION_SVC_DB_URI
Expand All @@ -28,8 +19,6 @@ services:
user-service:
build:
context: ./user-service
ports:
- $USER_SVC_PORT:$USER_SVC_PORT
environment:
- PORT=$USER_SVC_PORT
- DB_URI=$USER_SVC_DB_URI
Expand All @@ -40,15 +29,31 @@ services:
matching-service:
build:
context: ./matching-service
ports:
- $MATCHING_SVC_PORT:$MATCHING_SVC_PORT
environment:
- PORT=$MATCHING_SVC_PORT
- REDIS_HOST=redis
- REDIS_PORT=$REDIS_PORT
depends_on:
- redis

api-gateway:
image: nginx:1.26
volumes:
- ./api-gateway/templates:/etc/nginx/templates
ports:
- $API_GATEWAY_PORT:$API_GATEWAY_PORT
environment:
- PORT=$API_GATEWAY_PORT
- FRONTEND_PORT=$FRONTEND_PORT
- USER_SVC_PORT=$USER_SVC_PORT
- QUESTION_SVC_PORT=$QUESTION_SVC_PORT
- MATCHING_SVC_PORT=$MATCHING_SVC_PORT
depends_on:
- frontend
- user-service
- question-service
- matching-service

redis:
image: redis:7.4-alpine
restart: always
Expand All @@ -63,4 +68,4 @@ services:
ports:
- $REDIS_INSIGHT_PORT:$REDIS_INSIGHT_PORT # Expose RedisInsight UI on port 5540
depends_on:
- redis
- redis
8 changes: 2 additions & 6 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Base stage
FROM node:20-alpine AS base
ARG BASE_URI \
USER_SVC_PORT \
QUESTION_SVC_PORT \
MATCHING_SVC_PORT
API_GATEWAY_PORT
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile
ENV NEXT_PUBLIC_BASE_URI=$BASE_URI \
NEXT_PUBLIC_USER_SVC_PORT=$USER_SVC_PORT \
NEXT_PUBLIC_QUESTION_SVC_PORT=$QUESTION_SVC_PORT \
NEXT_PUBLIC_MATCHING_SVC_PORT=$MATCHING_SVC_PORT
NEXT_PUBLIC_API_GATEWAY_PORT=$API_GATEWAY_PORT

# Production build stage
FROM base AS build
Expand Down
19 changes: 11 additions & 8 deletions frontend/app/auth/auth-context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { userServiceUri } from "@/lib/api-uri";
import { AuthType, userServiceUri } from "@/lib/api-uri";
import { User, UserSchema } from "@/lib/schemas/user-schema";
import { useRouter } from "next/navigation";
import {
Expand Down Expand Up @@ -39,12 +39,15 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
}
if (token) {
setIsLoading(true);
fetch(`${userServiceUri(window.location.hostname)}/auth/verify-token`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
})
fetch(
`${userServiceUri(window.location.hostname, AuthType.Public)}/auth/verify-token`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
}
)
.then((res) => {
res.json().then((result) => {
setUser(result.data);
Expand All @@ -61,7 +64,7 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
// Login using email and password
const login = async (email: string, password: string): Promise<User> => {
const response = await fetch(
`${userServiceUri(window.location.hostname)}/auth/login`,
`${userServiceUri(window.location.hostname, AuthType.Public)}/auth/login`,
{
method: "POST",
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LoadingScreen from "@/components/common/loading-screen";
import AdminEditUserModal from "@/components/admin-user-management/admin-edit-user-modal";
import { PencilIcon, Trash2Icon } from "lucide-react";
import { User, UserArraySchema } from "@/lib/schemas/user-schema";
import { userServiceUri } from "@/lib/api-uri";
import { AuthType, userServiceUri } from "@/lib/api-uri";

const fetcher = async (url: string): Promise<User[]> => {
const token = localStorage.getItem("jwtToken");
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function AdminUserManagement() {
const auth = useAuth();

const { data, isLoading, mutate } = useSWR(
`${userServiceUri(window.location.hostname)}/users`,
`${userServiceUri(window.location.hostname, AuthType.Public)}/users`,
fetcher
);

Expand All @@ -69,7 +69,7 @@ export default function AdminUserManagement() {
}

const response = await fetch(
`${userServiceUri(window.location.hostname)}/users/${userId}`,
`${userServiceUri(window.location.hostname, AuthType.Public)}/users/${userId}`,
{
method: "DELETE",
headers: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/forget-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { AlertCircle } from "lucide-react";
import { userServiceUri } from "@/lib/api-uri";
import { AuthType, userServiceUri } from "@/lib/api-uri";

const ForgetPassword: React.FC = () => {
const [email, setEmail] = useState("");
Expand All @@ -36,7 +36,7 @@ const ForgetPassword: React.FC = () => {

try {
const response = await fetch(
`${userServiceUri(window.location.hostname)}/users/forget-password`,
`${userServiceUri(window.location.hostname, AuthType.Public)}/users/forget-password`,
{
method: "POST",
headers: {
Expand Down
Loading