Skip to content

Commit 3801480

Browse files
authored
Merge pull request #101 from CS3219-AY2324S1/clean-up-docker-files
Clean up docker files
2 parents 9eb74d5 + ebf1248 commit 3801480

File tree

15 files changed

+119
-73
lines changed

15 files changed

+119
-73
lines changed

ApiGatewayService/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ COPY . .
1717
EXPOSE 3001
1818

1919
# Define the command to start your API gateway
20-
CMD [ "npm", "run", "dev"]
20+
CMD [ "npm", "run", "dev" ]

ApiGatewayService/src/index.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
11
import express from "express";
22
import httpProxy from "http-proxy";
33
import cors from "cors";
4-
// import http from 'http';
5-
// import { Server } from 'socket.io';
64

75
const app = express();
86
const proxy = httpProxy.createProxyServer();
97
app.use(cors());
108

11-
// // Create an HTTP server and attach Socket.IO to it
12-
// const server = http.createServer(app);
13-
// const io = new Server(server, {
14-
// cors: {
15-
// origin: '*',
16-
// },
17-
// path: 'ws'
18-
// });
19-
209
// Define routes for each backend service for local development
10+
// app.use('/questionservice', (req, res) => {
11+
// proxy.web(req, res, { target: 'http://localhost:3002' });
12+
// });
13+
// app.use('/authservice', (req, res) => {
14+
// proxy.web(req, res, { target: 'http://localhost:3003' });
15+
// });
16+
// app.use('/userservice', (req, res) => {
17+
// proxy.web(req, res, { target: 'http://localhost:3004' });
18+
// });
19+
20+
// Define routes for each backend service for production/docker containers
2121
app.use("/questionservice", (req, res) => {
2222
proxy.web(req, res, { target: "http://question-service:3002" });
2323
});
24-
2524
app.use("/authservice", (req, res) => {
2625
proxy.web(req, res, { target: "http://auth-service:3003" });
2726
});
28-
2927
app.use("/userservice", (req, res) => {
3028
proxy.web(req, res, { target: "http://user-service:3004" });
3129
});
3230

33-
app.use("/matchingservice", (req, res) => {
34-
proxy.web(req, res, { target: "http://matching-service:3005" });
35-
});
36-
3731
// Start the server
3832
app.listen(3001, () => {
3933
console.log("API Gateway listening on port 3001");

ChatService/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ RUN npm install
1313
# Bundle your app source code into the container
1414
COPY . .
1515

16-
# Expose the port on which your Auth service will run
16+
# Expose the port on which your Chat service will run
1717
EXPOSE 3007
1818

19-
# Define the command to start your Auth service
19+
# Define the command to start your Chat service
2020
CMD [ "npm", "run", "dev"]

CollabService/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Use an official Node.js runtime as a parent image
22
FROM node:14
3+
34
# Set the working directory in the container
45
WORKDIR /usr/src/collab-service
56

@@ -12,8 +13,8 @@ RUN npm install
1213
# Bundle your app source code into the container
1314
COPY . .
1415

15-
# Expose the port on which your Auth service will run
16+
# Expose the port on which your Collab service will run
1617
EXPOSE 3006
1718

18-
# Define the command to start your Auth service
19+
# Define the command to start your Collab service
1920
CMD [ "npm", "run", "dev"]

MatchingService/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ RUN npm install
1313
# Bundle your app source code into the container
1414
COPY . .
1515

16-
# Expose the port on which your Auth service will run
16+
# Expose the port on which your Matching service will run
1717
EXPOSE 3005
1818

19-
# Define the command to start your Auth service
19+
# Define the command to start your Matching service
2020
CMD [ "npm", "run", "dev"]

QuestionService/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ RUN npm install
1313
# Bundle your app source code into the container
1414
COPY . .
1515

16-
# Expose the port on which your Auth service will run
16+
# Expose the port on which your Question service will run
1717
# EXPOSE 3002
1818

19-
# Define the command to start your Auth service
19+
# Define the command to start your Question service
2020
CMD [ "npm", "run", "dev"]

QuestionService/javascript/question/question.controller.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ const firestore_1 = require("firebase/firestore");
1515
function handleGetQuestions(req, res) {
1616
return __awaiter(this, void 0, void 0, function* () {
1717
try {
18-
// console.log(req.query.email);
19-
// const { email } = req.query;
18+
console.log("getting questions");
19+
const { token } = req.query;
20+
if (!token) {
21+
res.status(500).send("unauthorized access");
22+
}
23+
if (typeof token === "string") {
24+
const response = yield (0, question_service_1.isValidToken)(token);
25+
if (!response) {
26+
res.status(500).send("unauthorized access");
27+
}
28+
}
29+
else {
30+
res.status(500).send("invalid params");
31+
}
2032
const query = yield (0, firestore_1.getDocs)((0, firestore_1.collection)(question_service_1.db, "questions"));
2133
const result = yield Promise.all(query.docs.map((d) => __awaiter(this, void 0, void 0, function* () {
2234
const q = d.data();

QuestionService/javascript/question/question.service.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
Object.defineProperty(exports, "__esModule", { value: true });
12-
exports.addQuestion = exports.updateQuestion = exports.deleteQuestion = exports.db = void 0;
12+
exports.isValidToken = exports.addQuestion = exports.updateQuestion = exports.deleteQuestion = exports.db = void 0;
1313
const app_1 = require("firebase/app");
1414
const firestore_1 = require("firebase/firestore");
1515
const firebase_config_1 = require("../firebase/firebase.config");
@@ -61,3 +61,24 @@ function addQuestion(question) {
6161
});
6262
}
6363
exports.addQuestion = addQuestion;
64+
function isValidToken(token) {
65+
return __awaiter(this, void 0, void 0, function* () {
66+
try {
67+
const q = (0, firestore_1.query)((0, firestore_1.collection)(exports.db, "users"));
68+
const querySnapshot = yield (0, firestore_1.getDocs)(q);
69+
const tokens = new Set();
70+
querySnapshot.forEach((doc) => {
71+
const user = doc.data();
72+
tokens.add(user.token);
73+
});
74+
if (tokens.has(token)) {
75+
return Promise.resolve(true);
76+
}
77+
return Promise.resolve(false);
78+
}
79+
catch (error) {
80+
return Promise.reject(error);
81+
}
82+
});
83+
}
84+
exports.isValidToken = isValidToken;

QuestionService/src/question/question.controller.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ export async function handleGetQuestions(req: Request, res: Response) {
2929
console.log("getting questions");
3030
const { token } = req.query;
3131
if (!token) {
32-
res.status(500).send("unauthorized access");
32+
console.log("unauthorized access");
33+
return res.status(401).send("unauthorized access");
3334
}
3435
if (typeof token === "string") {
3536
const response = await isValidToken(token);
3637
if (!response) {
37-
res.status(500).send("unauthorized access");
38+
console.log("unauthorized access");
39+
return res.status(401).send("unauthorized access");
3840
}
3941
} else {
40-
res.status(500).send("invalid params");
42+
console.log("invalid params");
43+
return res.status(500).send("invalid params");
4144
}
4245
const query = await getDocs(collection(db, "questions"));
4346
const result = await Promise.all(
@@ -59,13 +62,15 @@ export async function handleGetQuestions(req: Request, res: Response) {
5962
);
6063

6164
if (result.length > 0) {
62-
res.status(200).send(result);
65+
console.log("questions retrieved");
66+
return res.status(200).send(result);
6367
} else {
64-
res.status(500).send("no questions");
68+
console.log("no questions");
69+
return res.status(500).send("no questions");
6570
}
6671
} catch (error) {
6772
console.error(error);
68-
res.status(500).send(error);
73+
return res.status(500).send(error);
6974
}
7075
}
7176

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Assignment 4
2+
Requirements:
3+
- Docker
4+
5+
Steps:
6+
1. Open up your Terminal or command line
7+
2. Navigate to the project's base directory, where the docker-compose.yml is
8+
3. Run `docker-compose up --build`
9+
4. Wait for the containers to finish building and run
10+
5. Open up your Docker dashboard, the new images and containers should be visible:
11+
1. frontend
12+
2. api-gateway
13+
3. question-service
14+
4. user-service
15+
5. auth-service
16+
6. Open your browser and go to the address `http://localhost:3000/`
17+
7. Login into the website using our admin account
18+
8. Feel free to test our Questions and User service features. For example:
19+
1. Managing Questions
20+
1. Click on the 'Manage Questions' button in the NavBar above
21+
2. Click on 'Add Question' button
22+
3. Type in a dummy question and click 'Submit'
23+
4. Go back to the home page to and check that the new question is in the question table
24+
5. Check the Terminal/command line/Logs in the question-service container in Docker dashboard to view the message logs
25+
2. Managing User Profile
26+
1. Click on the top right profile button
27+
2. Select 'Profile'
28+
3. Click on 'Edit Profile' button
29+
4. Change any profile details, then click on 'Save'
30+
5. Check the Terminal/command line/Logs in the user-service container in Docker dashboard to view the message logs

0 commit comments

Comments
 (0)