Skip to content

Commit ce7db21

Browse files
committed
init matching service
1 parent db23cec commit ce7db21

File tree

11 files changed

+1278
-1
lines changed

11 files changed

+1278
-1
lines changed

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ services:
4444
- peerprep-network
4545
env_file:
4646
- ./user-service/.env
47+
matching-service:
48+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/matching-svc:latest
49+
build:
50+
context: ./matching-service
51+
dockerfile: Dockerfile
52+
target: development
53+
volumes:
54+
- ./matching-service:/app
55+
- ./matching-service/node_modules:/app/node_modules
56+
ports:
57+
- "5001:5001"
58+
networks:
59+
- peerprep-network
60+
env_file:
61+
- ./matching-service/.env.dev
4762
networks:
4863
peerprep-network:
4964
driver: bridge

matching-service/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
dist

matching-service/.env.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MONGODB_CONNECTION_STRING=mongodb+srv://cs3219g11:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
2+
PORT=5001

matching-service/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# npm
2+
node_modules
3+
*.log
4+
*.gz
5+
6+
# Coveralls
7+
.nyc_output
8+
coverage
9+
10+
# Benchmarking
11+
benchmarks/graphs
12+
13+
# ignore additional files using core.excludesFile
14+
# https://git-scm.com/docs/gitignore

matching-service/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Base stage for both dev and prod
2+
FROM node:18-alpine AS base
3+
4+
# Install pnpm globally
5+
RUN npm install -g pnpm
6+
7+
# Set the working directory in the container
8+
WORKDIR /app
9+
10+
# Copy package.json and pnpm-lock.yaml
11+
COPY package.json ./
12+
13+
RUN pnpm install
14+
15+
# Development stage
16+
FROM base AS development
17+
18+
COPY src ./src
19+
COPY tsconfig.json ./
20+
21+
# Note: Don't expose ports here, Compose will handle that for us
22+
23+
CMD ["pnpm", "dev"]
24+
25+
26+
# Production stage
27+
FROM base AS production
28+
ENV NODE_ENV=production
29+
ENV PORT=5001
30+
31+
COPY src ./src
32+
COPY tsconfig.json ./
33+
34+
EXPOSE ${PORT}
35+
36+
CMD ["pnpm", "start"]

matching-service/dist/app.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
25+
var __importDefault = (this && this.__importDefault) || function (mod) {
26+
return (mod && mod.__esModule) ? mod : { "default": mod };
27+
};
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
const express_1 = __importDefault(require("express"));
30+
const cors_1 = __importDefault(require("cors"));
31+
const dotenv = __importStar(require("dotenv"));
32+
dotenv.config({ path: '.env.dev' });
33+
const app = (0, express_1.default)();
34+
const PORT = process.env.PORT || 5001; // 5001 to prevent conflicts
35+
app.use(express_1.default.json());
36+
app.use((0, cors_1.default)()); // config cors so that front-end can use
37+
app.options('*', (0, cors_1.default)());
38+
const apiVersion = '/api/v1';
39+
// Middleware to handle CORS and preflight requests
40+
app.use((req, res, next) => {
41+
res.header('Access-Control-Allow-Origin', '*'); // Allow all origins
42+
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
43+
// Handle preflight (OPTIONS) request before PUT or POST
44+
if (req.method === 'OPTIONS') {
45+
res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, PATCH');
46+
return res.status(200).json({});
47+
}
48+
// Continue to next middleware
49+
next();
50+
});
51+
// Start the server
52+
app.listen(PORT, () => {
53+
console.log(`Server is running on port ${PORT}`);
54+
});

matching-service/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "matching-service",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "nodemon src/app.ts",
8+
"start": "tsc && node dist/app.js",
9+
"build": "tsc",
10+
"format": "prettier --write \"src/**/*.ts\"",
11+
"test": "echo \"Error: no test specified\" && exit 1",
12+
"pre-commit": "pnpm format && git add -u"
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "ISC",
17+
"dependencies": {
18+
"cors": "^2.8.5",
19+
"dotenv": "^16.4.5",
20+
"express": "^4.21.1"
21+
},
22+
"devDependencies": {
23+
"@types/cors": "^2.8.17",
24+
"@types/dotenv": "^8.2.0",
25+
"@types/express": "^5.0.0",
26+
"nodemon": "^3.1.7",
27+
"prettier": "^3.3.3",
28+
"ts-node": "^10.9.2",
29+
"typescript": "^5.6.3"
30+
}
31+
}

0 commit comments

Comments
 (0)