Skip to content

Commit 0551489

Browse files
committed
Refactor env
1 parent b52957e commit 0551489

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

backend/user-service/src/model/repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import UserModel, { IUser } from "./user-model";
2-
import "dotenv/config";
2+
import dotenv from "dotenv";
33
import { connect } from "mongoose";
44

5+
dotenv.config();
6+
57
export async function connectToDB() {
68
const mongoDBUri: string | undefined =
79
process.env.NODE_ENV === "production"
810
? process.env.MONGO_CLOUD_URI
911
: process.env.MONGO_LOCAL_URI;
1012

13+
console.log(mongoDBUri);
14+
1115
if (!mongoDBUri) {
1216
throw new Error("MongoDB URI is not provided");
1317
}

frontend/src/utils/api.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import axios from "axios";
22

3-
const usersUrl = "http://localhost:3001/api";
4-
const questionsUrl = "http://localhost:3000/api/questions";
5-
const codeExecutionUrl = "http://localhost:3004/api/run";
6-
const qnHistoriesUrl = "http://localhost:3006/api/qnhistories";
3+
const usersUrl =
4+
import.meta.env.VITE_USER_SERVICE_URL ?? "http://localhost:3001/api";
5+
const questionsUrl =
6+
import.meta.env.VITE_QN_SERVICE_URL ?? "http://localhost:3000/api/questions";
7+
const codeExecutionUrl =
8+
import.meta.env.VITE_CODE_EXEC_SERVICE_URL ?? "http://localhost:3004/api/run";
9+
const qnHistoriesUrl =
10+
import.meta.env.VITE_QN_HIST_SERVICE_URL ??
11+
"http://localhost:3006/api/qnhistories";
712

813
export const questionClient = axios.create({
914
baseURL: questionsUrl,

frontend/src/utils/collabSocket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export type CollabSessionData = {
3232
awareness: Awareness;
3333
};
3434

35-
const COLLAB_SOCKET_URL = "http://localhost:3003";
35+
const COLLAB_SOCKET_URL =
36+
import.meta.env.VITE_COLLAB_SERVICE_URL ?? "http://localhost:3003";
3637
export const collabSocket = io(COLLAB_SOCKET_URL, {
3738
reconnectionAttempts: 3,
3839
autoConnect: false,

frontend/src/utils/communicationSocket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export enum CommunicationEvents {
1313
DISCONNECTED = "disconnected",
1414
}
1515

16-
const COMMUNICATION_SOCKET_URL = "http://localhost:3005";
16+
const COMMUNICATION_SOCKET_URL =
17+
import.meta.env.VITE_COMM_SERVICE_URL ?? "http://localhost:3005";
1718

1819
export const communicationSocket = io(COMMUNICATION_SOCKET_URL, {
1920
reconnectionAttempts: 3,

frontend/src/utils/matchSocket.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { io } from "socket.io-client";
22

3-
const MATCH_SOCKET_URL = "http://localhost:3002";
3+
const MATCH_SOCKET_URL =
4+
import.meta.env.VITE_MATCH_SERVICE_URL ?? "http://localhost:3002";
5+
6+
console.log(import.meta.env.VITE_MATCH_SERVICE_URL);
47

58
export const matchSocket = io(MATCH_SOCKET_URL, {
69
reconnectionAttempts: 3,

0 commit comments

Comments
 (0)