forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
59 lines (50 loc) · 1.41 KB
/
index.ts
File metadata and controls
59 lines (50 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express, { type Express } from 'express';
import cors from 'cors';
import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc';
import cartRouter from './routes/cart';
const app: Express = express();
const PORT: string = process.env.PORT ?? '3002';
// Swagger configuration
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'Cart Service API',
version: '1.0.0',
description: 'A cart management service with interactive documentation',
},
servers: [
{
url: `http://localhost:${PORT}`,
description: 'Development server',
},
],
},
apis: ['./src/routes/cart.ts'],
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
// Middleware
app.use(
cors({
origin: '*',
}),
);
app.use(express.json());
// Swagger UI
// eslint-disable-next-line @typescript-eslint/no-explicit-any
app.use('/docs', ...(swaggerUi.serve as any), swaggerUi.setup(swaggerSpec) as any);
// Routes
app.use('/api/cart', cartRouter);
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'OK', timestamp: new Date().toISOString() });
});
// Only start server if not in test environment
if (process.env.NODE_ENV !== 'test') {
app.listen(PORT, () => {
console.log(`Cart service running on port ${PORT}`);
console.log(`Swagger UI available at http://localhost:${PORT}/docs`);
});
}
export default app;