File tree Expand file tree Collapse file tree 12 files changed +77
-30
lines changed Expand file tree Collapse file tree 12 files changed +77
-30
lines changed Original file line number Diff line number Diff line change 9
9
"build:prod" : " env-cmd -f .env.prod tsc && tsc-alias" ,
10
10
"start:prod" : " env-cmd -f .env.local node dist/index.js" ,
11
11
"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" ,
13
13
"db:inspect" : " env-cmd -f .env.local drizzle-kit studio" ,
14
14
"fmt" : " prettier --config .prettierrc src --write" ,
15
15
"test" : " echo \" Error: no test specified\" && exit 1"
19
19
"license" : " ISC" ,
20
20
"description" : " " ,
21
21
"dependencies" : {
22
+ "cors" : " ^2.8.5" ,
22
23
"drizzle-orm" : " ^0.33.0" ,
23
24
"env-cmd" : " ^10.1.0" ,
24
25
"express" : " ^4.21.0" ,
26
+ "http-status-codes" : " ^2.3.0" ,
25
27
"pino" : " ^9.4.0" ,
26
28
"pino-http" : " ^10.3.0" ,
27
29
"postgres" : " ^3.4.4"
28
30
},
29
31
"devDependencies" : {
32
+ "@types/cors" : " ^2.8.17" ,
30
33
"@types/express" : " ^4.17.21" ,
31
34
"@types/node" : " ^22.5.5" ,
32
35
"drizzle-kit" : " ^0.24.2" ,
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change
1
+ import { EXPRESS_PORT } from '@/config' ;
1
2
import { logger } from '@/lib/utils' ;
2
3
import app , { dbHealthCheck } from '@/server' ;
3
4
4
- const port = process . env . PORT || 8001 ;
5
+ const port = Number . parseInt ( EXPRESS_PORT || ' 8001' ) ;
5
6
6
7
const listenMessage = `App listening on port: ${ port } ` ;
7
8
app . listen ( port , ( ) => {
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
import { exit } from 'process' ;
2
2
3
+ import cors from 'cors' ;
4
+ import { sql } from 'drizzle-orm' ;
3
5
import express , { json } from 'express' ;
6
+ import { StatusCodes } from 'http-status-codes' ;
4
7
import pino from 'pino-http' ;
5
- import { sql } from 'drizzle-orm' ;
6
8
7
9
import { config , db } from '@/lib/db' ;
8
10
import { logger } from '@/lib/utils' ;
11
+ import { UI_HOST } from './config' ;
9
12
10
13
const app = express ( ) ;
11
14
app . use ( pino ( ) ) ;
12
15
app . use ( json ( ) ) ;
16
+ app . use (
17
+ cors ( {
18
+ origin : [ UI_HOST ] ,
19
+ credentials : true ,
20
+ } )
21
+ ) ;
13
22
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' ) ) ;
19
25
20
26
export const dbHealthCheck = async ( ) => {
21
27
try {
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 1
1
import { logger } from '@/lib/utils' ;
2
2
import app , { dbHealthCheck } from '@/server' ;
3
+ import { EXPRESS_PORT } from '@/config' ;
3
4
4
- const port = Number . parseInt ( process . env . EXPRESS_PORT ?? '8001' ) ;
5
+ const port = Number . parseInt ( EXPRESS_PORT ?? '8001' ) ;
5
6
6
7
const listenMessage = `App listening on port: ${ port } ` ;
7
8
app . listen ( port , ( ) => {
Original file line number Diff line number Diff line change 1
1
import { exit } from 'process' ;
2
2
3
3
import cors from 'cors' ;
4
- import express , { json } from 'express' ;
5
- import pino from 'pino-http' ;
6
4
import { sql } from 'drizzle-orm' ;
5
+ import express , { json } from 'express' ;
7
6
import helmet from 'helmet' ;
7
+ import { StatusCodes } from 'http-status-codes' ;
8
+ import pino from 'pino-http' ;
8
9
9
- import questionsRouter from '@/routes/question' ;
10
10
import { config , db } from '@/lib/db' ;
11
11
import { logger } from '@/lib/utils' ;
12
+ import questionsRouter from '@/routes/question' ;
13
+ import { UI_HOST } from '@/config' ;
12
14
13
15
const app = express ( ) ;
14
16
app . use ( pino ( ) ) ;
15
17
app . use ( json ( ) ) ;
16
18
app . use ( helmet ( ) ) ;
17
19
app . use (
18
20
cors ( {
19
- origin : [ process . env . PEERPREP_UI_HOST ! ] ,
21
+ origin : [ UI_HOST ] ,
20
22
credentials : true ,
21
23
} )
22
24
) ;
23
25
24
26
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' ) ) ;
30
30
31
31
export const dbHealthCheck = async ( ) => {
32
32
try {
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ import 'dotenv/config';
2
2
3
3
export const JWT_SECRET_KEY = process . env . EXPRESS_JWT_SECRET_KEY ! ;
4
4
5
+ export const UI_HOST = process . env . PEERPREP_UI_HOST ! ;
6
+
7
+ export const EXPRESS_PORT = process . env . EXPRESS_PORT ;
8
+
5
9
export const dbConfig = {
6
10
host : process . env . EXPRESS_DB_HOST ! ,
7
11
port : Number . parseInt ( process . env . EXPRESS_DB_PORT ! ) ,
Original file line number Diff line number Diff line change 1
- import 'dotenv/config' ;
2
-
3
- import app , { dbHealthCheck } from '@/server' ;
1
+ import { EXPRESS_PORT } from '@/config' ;
4
2
import { logger } from '@/lib/utils' ;
3
+ import app , { dbHealthCheck } from '@/server' ;
5
4
6
- const port = Number . parseInt ( process . env . EXPRESS_PORT ?? '8001' ) ;
5
+ const port = Number . parseInt ( EXPRESS_PORT ?? '8001' ) ;
7
6
8
7
const listenMessage = `App listening on port: ${ port } ` ;
9
8
app . listen ( port , async ( ) => {
You can’t perform that action at this time.
0 commit comments