|
1 |
| -import express, { Express, Request, Response } from "express"; |
| 1 | +import express, { Request, Response } from "express"; |
2 | 2 | import dotenv from "dotenv";
|
3 |
| -import path from "path"; |
4 | 3 | import swaggerUi from "swagger-ui-express";
|
5 | 4 | import yaml from "yaml";
|
6 | 5 | import fs from "fs";
|
7 | 6 |
|
8 |
| -const envFilePath = path.join( |
9 |
| - path.resolve(path.dirname(path.dirname(__dirname))), |
10 |
| - ".env", |
11 |
| -); |
| 7 | +import connectDB from "./config/db.ts"; |
| 8 | +import questionRoutes from "./src/routes/questionRoutes.ts"; |
| 9 | + |
| 10 | +dotenv.config(); |
12 | 11 |
|
13 | 12 | const file = fs.readFileSync("./swagger.yml", "utf-8");
|
14 | 13 | const swaggerDocument = yaml.parse(file);
|
15 | 14 |
|
16 |
| -dotenv.config({ path: envFilePath }); |
17 |
| - |
18 |
| -const app: Express = express(); |
| 15 | +const app = express(); |
19 | 16 |
|
20 |
| -const PORT = process.env.QUESTION_SERVICE_PORT || 3000; |
| 17 | +connectDB(); |
21 | 18 |
|
| 19 | +app.use(express.json()); |
| 20 | +app.use("/api", questionRoutes); |
| 21 | +app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); |
22 | 22 | app.get("/", (req: Request, res: Response) => {
|
23 | 23 | res.status(200).json({ message: "Hello world from question service" });
|
24 | 24 | });
|
25 | 25 |
|
26 |
| -app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); |
27 |
| - |
28 |
| -app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); |
| 26 | +export default app; |
0 commit comments