Skip to content

Commit f71e7c0

Browse files
authored
Merge pull request #80 from CS3219-AY2425S1/feat/17-api-gateway
2 parents d043bfe + aa3e452 commit f71e7c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7096
-4237
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ jobs:
2828
run: "gcloud info"
2929

3030
- name: "Trigger Cloud Build"
31-
env:
32-
NEXT_PUBLIC_QUESTION_SERVICE_URL: ${{ secrets.NEXT_PUBLIC_QUESTION_SERVICE_URL }}
33-
NEXT_PUBLIC_AUTH_SERVICE_URL: ${{ secrets.NEXT_PUBLIC_AUTH_SERVICE_URL }}
34-
AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }}
35-
QUESTION_SERVICE_URL: ${{ secrets.QUESTION_SERVICE_URL }}
31+
env: # have to use env here as cant use secrets in kubernetes for nextJS
32+
NEXT_PUBLIC_API_GATEWAY_URL: ${{ secrets.NEXT_PUBLIC_API_GATEWAY_URL }}
3633
run: |
37-
gcloud builds submit --config cloudbuild.yaml --substitutions _NEXT_PUBLIC_QUESTION_SERVICE_URL="$NEXT_PUBLIC_QUESTION_SERVICE_URL",_NEXT_PUBLIC_AUTH_SERVICE_URL="$NEXT_PUBLIC_AUTH_SERVICE_URL",_AUTH_SERVICE_URL="$AUTH_SERVICE_URL",_QUESTION_SERVICE_URL="$QUESTION_SERVICE_URL"
34+
gcloud builds submit --config cloudbuild.yaml --substitutions _NEXT_PUBLIC_API_GATEWAY_URL="$NEXT_PUBLIC_API_GATEWAY_URL"

.gitignore

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

3-
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.js
7-
.yarn/install-state.gz
8-
.vscode
3+
# Dependencies
4+
node_modules/
95

10-
# testing
11-
/coverage
6+
# Build output
7+
dist/
8+
build/
129

13-
# next.js
14-
/.next/
15-
/out/
10+
# Logs
11+
*.log
1612

17-
# production
18-
/build
13+
# Environment variables
14+
.env
1915

16+
# IDE files
17+
.vscode/
18+
.idea/
19+
20+
# OS files
21+
.DS_Store
22+
Thumbs.db
2023
# pnpm stores
2124
*/.pnpm-store
2225

api-gateway/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
.env
3+
.env.*
4+
/dist
5+
combined.log
6+
error.log

api-gateway/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 80
6+
}

api-gateway/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
COPY pnpm-lock.yaml ./
13+
14+
RUN pnpm install
15+
16+
# Development stage
17+
FROM base AS development
18+
19+
COPY src ./src
20+
COPY tsconfig.json ./
21+
22+
# Note: Don't expose ports here, Compose will handle that for us
23+
24+
CMD ["pnpm", "dev"]
25+
26+
27+
# Production stage
28+
FROM base AS production
29+
ENV NODE_ENV=production
30+
ENV PORT=8001
31+
32+
COPY src ./src
33+
COPY tsconfig.json ./
34+
COPY .env.production ./
35+
36+
EXPOSE ${PORT}
37+
38+
CMD ["pnpm", "start"]

api-gateway/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "api-gateway",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "nodemon --exec ts-node 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+
"@stomp/stompjs": "^7.0.0",
19+
"cors": "^2.8.5",
20+
"dotenv": "^16.4.5",
21+
"express": "^4.21.1",
22+
"http-proxy-middleware": "^3.0.3",
23+
"jsonwebtoken": "^9.0.2",
24+
"winston": "^3.15.0",
25+
"ws": "^8.13.0"
26+
},
27+
"devDependencies": {
28+
"@types/cors": "^2.8.17",
29+
"@types/express": "^5.0.0",
30+
"@types/jsonwebtoken": "^9.0.7",
31+
"@types/node": "^22.7.7",
32+
"@types/ws": "^8.5.12",
33+
"eslint-config-prettier": "^9.1.0",
34+
"eslint-plugin-prettier": "^5.2.1",
35+
"nodemon": "^3.1.7",
36+
"prettier": "^3.3.3",
37+
"ts-node": "^10.9.2",
38+
"typescript": "^5.6.3"
39+
}
40+
}

0 commit comments

Comments
 (0)