Skip to content

Commit 01b7a94

Browse files
committed
fix: minor changes
1 parent b746101 commit 01b7a94

4 files changed

Lines changed: 75 additions & 27 deletions

File tree

payment-service/Dockerfile

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
FROM node:22-alpine
1+
FROM node:22-alpine AS base
2+
3+
FROM base AS development
24

35
WORKDIR /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" ]

payment-service/index.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

payment-service/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
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": "",

payment-service/src/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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();

0 commit comments

Comments
 (0)