Skip to content

Commit

Permalink
Merge pull request #114 from jolynloh/deployment
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
ruiqi7 authored Nov 12, 2024
2 parents 66d6b0e + 3f9359c commit 3fb91e0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const verifyToken = (
.then(() => next())
.catch((err) => {
console.log(err.response);
return res.status(err.response.status).json(err.response.data);
return res.status(err.response?.status).json(err.response?.data);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const verifyAdminToken = (
.then(() => next())
.catch((err) => {
console.log(err.response);
return res.status(err.response.status).json(err.response.data);
return res.status(err.response?.status).json(err.response?.data);
});
};
6 changes: 5 additions & 1 deletion backend/question-service/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import app from "./app.ts";
import connectDB from "./config/db.ts";
// import { seedQuestions } from "./scripts/seed.ts";

const PORT = process.env.SERVICE_PORT || 3000;

if (process.env.NODE_ENV !== "test") {
connectDB()
.then(() => {
console.log("MongoDB Connected!");
// seedQuestions();

app.listen(PORT, () => {
const server = app.listen(PORT, () => {
console.log(
`Question service server listening on http://localhost:${PORT}`,
);
});

server.keepAliveTimeout = 70 * 1000; // set timeout value to > load balancer idle timeout (60s)
})
.catch((err) => {
console.error("Failed to connect to DB");
Expand Down
6 changes: 5 additions & 1 deletion backend/user-service/src/model/repository.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import UserModel, { IUser } from "./user-model";
import "dotenv/config";
import dotenv from "dotenv";
import { connect } from "mongoose";

dotenv.config();

export async function connectToDB() {
const mongoDBUri: string | undefined =
process.env.NODE_ENV === "production"
? process.env.MONGO_CLOUD_URI
: process.env.MONGO_LOCAL_URI;

console.log(mongoDBUri);

if (!mongoDBUri) {
throw new Error("MongoDB URI is not provided");
}
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import axios from "axios";

const usersUrl = "http://localhost:3001/api";
const questionsUrl = "http://localhost:3000/api/questions";
const codeExecutionUrl = "http://localhost:3004/api/run";
const qnHistoriesUrl = "http://localhost:3006/api/qnhistories";
const usersUrl =
import.meta.env.VITE_USER_SERVICE_URL ?? "http://localhost:3001/api";
const questionsUrl =
import.meta.env.VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions";
const codeExecutionUrl =
import.meta.env.VITE_CODE_EXEC_SERVICE_URL ?? "http://localhost:3004/api/run";
const qnHistoriesUrl =
import.meta.env.VITE_QN_HIST_SERVICE_URL ??
"http://localhost:3006/api/qnhistories";

export const questionClient = axios.create({
baseURL: questionsUrl,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/collabSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export type CollabSessionData = {
awareness: Awareness;
};

const COLLAB_SOCKET_URL = "http://localhost:3003";
const COLLAB_SOCKET_URL =
import.meta.env.VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003";

export const collabSocket = io(COLLAB_SOCKET_URL, {
reconnectionAttempts: 5,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/communicationSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export enum CommunicationEvents {
DISCONNECTED = "disconnected",
}

const COMMUNICATION_SOCKET_URL = "http://localhost:3005";
const COMMUNICATION_SOCKET_URL =
import.meta.env.VITE_COMM_SERVICE_URL ?? "http://localhost:3005";

export const communicationSocket = io(COMMUNICATION_SOCKET_URL, {
reconnectionAttempts: 3,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/matchSocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { io } from "socket.io-client";
import { getToken } from "./token";

const MATCH_SOCKET_URL = "http://localhost:3002";
const MATCH_SOCKET_URL =
import.meta.env.VITE_MATCH_SERVICE_URL ?? "http://localhost:3002";

export const matchSocket = io(MATCH_SOCKET_URL, {
reconnectionAttempts: 3,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"husky": "^9.1.6"
},
"scripts": {
"prepare": "husky"
"prepare": "command -v husky && husky || true"
}
}

0 comments on commit 3fb91e0

Please sign in to comment.