Skip to content

Commit f14a68c

Browse files
committed
PEER-255 Standardize config for collab and qn services
Signed-off-by: SeeuSim <[email protected]>
1 parent 771a297 commit f14a68c

File tree

12 files changed

+77
-30
lines changed

12 files changed

+77
-30
lines changed

backend/collaboration/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:prod": "env-cmd -f .env.prod tsc && tsc-alias",
1010
"start:prod": "env-cmd -f .env.local node dist/index.js",
1111
"db:generate": "env-cmd -f .env.local drizzle-kit generate",
12-
"db:migrate": "env-cmd -f .env.local tsx drizzle.migrate.ts",
12+
"db:migrate": "env-cmd -f .env.local tsx ./src/lib/db/migrate.ts",
1313
"db:inspect": "env-cmd -f .env.local drizzle-kit studio",
1414
"fmt": "prettier --config .prettierrc src --write",
1515
"test": "echo \"Error: no test specified\" && exit 1"
@@ -19,14 +19,17 @@
1919
"license": "ISC",
2020
"description": "",
2121
"dependencies": {
22+
"cors": "^2.8.5",
2223
"drizzle-orm": "^0.33.0",
2324
"env-cmd": "^10.1.0",
2425
"express": "^4.21.0",
26+
"http-status-codes": "^2.3.0",
2527
"pino": "^9.4.0",
2628
"pino-http": "^10.3.0",
2729
"postgres": "^3.4.4"
2830
},
2931
"devDependencies": {
32+
"@types/cors": "^2.8.17",
3033
"@types/express": "^4.17.21",
3134
"@types/node": "^22.5.5",
3235
"drizzle-kit": "^0.24.2",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'dotenv/config';
2+
3+
export const JWT_SECRET_KEY = process.env.EXPRESS_JWT_SECRET_KEY!;
4+
5+
export const UI_HOST = process.env.PEERPREP_UI_HOST!;
6+
7+
export const EXPRESS_PORT = process.env.EXPRESS_PORT;
8+
9+
export const dbConfig = {
10+
host: process.env.EXPRESS_DB_HOST!,
11+
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
12+
database: process.env.POSTGRES_DB!,
13+
user: process.env.POSTGRES_USER,
14+
password: process.env.POSTGRES_PASSWORD,
15+
};

backend/collaboration/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { EXPRESS_PORT } from '@/config';
12
import { logger } from '@/lib/utils';
23
import app, { dbHealthCheck } from '@/server';
34

4-
const port = process.env.PORT || 8001;
5+
const port = Number.parseInt(EXPRESS_PORT || '8001');
56

67
const listenMessage = `App listening on port: ${port}`;
78
app.listen(port, () => {
File renamed without changes.

backend/collaboration/src/server.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { exit } from 'process';
22

3+
import cors from 'cors';
4+
import { sql } from 'drizzle-orm';
35
import express, { json } from 'express';
6+
import { StatusCodes } from 'http-status-codes';
47
import pino from 'pino-http';
5-
import { sql } from 'drizzle-orm';
68

79
import { config, db } from '@/lib/db';
810
import { logger } from '@/lib/utils';
11+
import { UI_HOST } from './config';
912

1013
const app = express();
1114
app.use(pino());
1215
app.use(json());
16+
app.use(
17+
cors({
18+
origin: [UI_HOST],
19+
credentials: true,
20+
})
21+
);
1322

14-
app.get('/', async (_req, res) => {
15-
res.json({
16-
message: 'OK',
17-
});
18-
});
23+
// Health Check for Docker
24+
app.get('/health', (_req, res) => res.status(StatusCodes.OK).send('OK'));
1925

2026
export const dbHealthCheck = async () => {
2127
try {

backend/question/src/config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'dotenv/config';
2+
3+
export const JWT_SECRET_KEY = process.env.EXPRESS_JWT_SECRET_KEY!;
4+
5+
export const UI_HOST = process.env.PEERPREP_UI_HOST!;
6+
7+
export const EXPRESS_PORT = process.env.EXPRESS_PORT;
8+
9+
export const dbConfig = {
10+
host: process.env.EXPRESS_DB_HOST!,
11+
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
12+
database: process.env.POSTGRES_DB!,
13+
user: process.env.POSTGRES_USER,
14+
password: process.env.POSTGRES_PASSWORD,
15+
};

backend/question/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { logger } from '@/lib/utils';
22
import app, { dbHealthCheck } from '@/server';
3+
import { EXPRESS_PORT } from '@/config';
34

4-
const port = Number.parseInt(process.env.EXPRESS_PORT ?? '8001');
5+
const port = Number.parseInt(EXPRESS_PORT ?? '8001');
56

67
const listenMessage = `App listening on port: ${port}`;
78
app.listen(port, () => {

backend/question/src/server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import { exit } from 'process';
22

33
import cors from 'cors';
4-
import express, { json } from 'express';
5-
import pino from 'pino-http';
64
import { sql } from 'drizzle-orm';
5+
import express, { json } from 'express';
76
import helmet from 'helmet';
7+
import { StatusCodes } from 'http-status-codes';
8+
import pino from 'pino-http';
89

9-
import questionsRouter from '@/routes/question';
1010
import { config, db } from '@/lib/db';
1111
import { logger } from '@/lib/utils';
12+
import questionsRouter from '@/routes/question';
13+
import { UI_HOST } from '@/config';
1214

1315
const app = express();
1416
app.use(pino());
1517
app.use(json());
1618
app.use(helmet());
1719
app.use(
1820
cors({
19-
origin: [process.env.PEERPREP_UI_HOST!],
21+
origin: [UI_HOST],
2022
credentials: true,
2123
})
2224
);
2325

2426
app.use('/questions', questionsRouter);
25-
app.get('/', async (_req, res) => {
26-
res.json({
27-
message: 'OK',
28-
});
29-
});
27+
28+
// Health Check for Docker
29+
app.get('/health', (_req, res) => res.status(StatusCodes.OK).send('OK'));
3030

3131
export const dbHealthCheck = async () => {
3232
try {

backend/user/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import 'dotenv/config';
22

33
export const JWT_SECRET_KEY = process.env.EXPRESS_JWT_SECRET_KEY!;
44

5+
export const UI_HOST = process.env.PEERPREP_UI_HOST!;
6+
7+
export const EXPRESS_PORT = process.env.EXPRESS_PORT;
8+
59
export const dbConfig = {
610
host: process.env.EXPRESS_DB_HOST!,
711
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),

backend/user/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import 'dotenv/config';
2-
3-
import app, { dbHealthCheck } from '@/server';
1+
import { EXPRESS_PORT } from '@/config';
42
import { logger } from '@/lib/utils';
3+
import app, { dbHealthCheck } from '@/server';
54

6-
const port = Number.parseInt(process.env.EXPRESS_PORT ?? '8001');
5+
const port = Number.parseInt(EXPRESS_PORT ?? '8001');
76

87
const listenMessage = `App listening on port: ${port}`;
98
app.listen(port, async () => {

0 commit comments

Comments
 (0)