Skip to content

Commit

Permalink
Add nginx proxy to microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
nknguyenhc committed Oct 1, 2024
1 parent 934f424 commit 283e870
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/question-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ app.use(cors({
}));

// Routes
app.use("/api/questions", questionRoutes);
app.use("/", questionRoutes);

// Start the server
app.listen(PORT, () => {
Expand Down
4 changes: 4 additions & 0 deletions frontend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
PORT=3000
REACT_APP_QUESTION_SERVICE_URL=http://localhost:3002
REACT_APP_USER_SERVICE_URL=http://localhost:3001

# In docker
REACT_APP_QUESTION_SERVICE_URL=http://localhost/api/questions/
REACT_APP_USER_SERVICE_URL=http://localhost/api/users/
8 changes: 8 additions & 0 deletions frontend/nginx/sites-enabled/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ server {
location / {
root /app;
}

location /api/questions/ {
proxy_pass http://question:3002/;
}

location /api/users/ {
proxy_pass http://user:3001/;
}
}
8 changes: 4 additions & 4 deletions frontend/src/services/question.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class QuestionService {
});

static async getQuestions(): Promise<Question[]> {
const response = await QuestionService.client.get("/api/questions");
const response = await QuestionService.client.get("/");
return response.data;
}

Expand All @@ -24,7 +24,7 @@ export default class QuestionService {
link: string,
): Promise<any> {
const body = verifyNewQuestion(id, title, description, categoriesString, complexity, link);
const response = await QuestionService.client.post("/api/questions", body);
const response = await QuestionService.client.post("/", body);
return response.data;
}

Expand All @@ -37,12 +37,12 @@ export default class QuestionService {
link: string,
): Promise<any> {
const body = verifyNewQuestion(id, title, description, categoriesString, complexity, link);
const response = await QuestionService.client.put(`/api/questions/${id}`, body);
const response = await QuestionService.client.put(`/${id}`, body);
return response.data;
}

static async deleteQuestion(id: number): Promise<any> {
const response = await QuestionService.client.delete(`/api/questions/${id}`);
const response = await QuestionService.client.delete(`/${id}`);
return response.data;
}
}

0 comments on commit 283e870

Please sign in to comment.