File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- FROM node:22-alpine
1+ FROM node:22-alpine AS base
2+
3+ FROM base AS development
24
35WORKDIR /app
46
5- COPY package*.json ./
7+ COPY package.json yarn.lock ./
8+
9+ RUN yarn global add nodemon && yarn install --verbose
10+
11+ COPY ./src .
12+
13+ EXPOSE 3001
614
7- RUN npm install
15+ CMD ["yarn" , "dev" ]
16+
17+ # Production image
18+
19+ # Builder Stage
20+ FROM base AS builder
21+
22+ WORKDIR /app
23+
24+ COPY package.json ./
25+
26+ # Install only production dependencies
27+ RUN yarn install --production --verbose && yarn cache clean
28+
29+ COPY ./src .
30+
31+ FROM node:22-alpine AS production
32+
33+ LABEL org.opencontainers.image.title="paymentservice"
34+ LABEL org.opencontainers.image.description="CraveDrop payment Service"
35+
36+ WORKDIR /app
837
9- COPY . .
38+ COPY --from=builder /app .
1039
11- EXPOSE 5002
40+ EXPOSE 3000
1241
13- CMD ["npm" , "start" ]
42+ CMD [ "node" , "index.js" ]
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 44 "main" : " index.js" ,
55 "type" : " module" ,
66 "scripts" : {
7- "test" : " echo \" Error: no test specified\" && exit 1" ,
8- "start" : " node index.js"
7+ "start" : " node src/index.js"
98 },
109 "keywords" : [],
1110 "author" : " " ,
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import dotenv from 'dotenv' ;
3+ import cors from 'cors' ;
4+ import paymentRoutes from './routes/payment.route.js' ;
5+
6+ dotenv . config ( ) ;
7+
8+ const app = express ( ) ;
9+ app . use ( express . json ( ) ) ;
10+
11+ // CORS configuration with frontend URL from environment
12+ const FRONTEND_URL = process . env . FRONTEND_URL || 'http://localhost:5173' ;
13+
14+ app . use ( cors ( {
15+ origin : FRONTEND_URL ,
16+ } ) ) ;
17+
18+ app . get ( '/api/payments/health' , ( req , res ) => {
19+ res . status ( 200 ) . json ( { status : 'ok' } ) ;
20+ } ) ;
21+
22+ // Payment routes
23+ app . use ( '/api/payments' , paymentRoutes ) ;
24+
25+ // Start server with error handling
26+ const PORT = process . env . PORT || 5002 ;
27+
28+ const startServer = async ( ) => {
29+ try {
30+ app . listen ( PORT , ( ) => {
31+ console . log ( `Payment service running on port ${ PORT } ` ) ;
32+ } ) ;
33+ } catch ( error ) {
34+ console . error ( 'Failed to start server:' , error . message ) ;
35+ process . exit ( 1 ) ;
36+ }
37+ } ;
38+
39+ startServer ( ) ;
You can’t perform that action at this time.
0 commit comments