| 1 | import express from "express"; |
| 2 | import cors from "cors"; |
| 3 | import helmet from "helmet"; |
| 4 | import dotenv from "dotenv"; |
| 5 | import authRoutes from "./routes"; |
| 6 | import { |
| 7 | corsOptions, |
| 8 | errorHandler, |
| 9 | healthCheck, |
| 10 | } from "../../../shared/middleware"; |
| 11 | |
| 12 | //load environment variables |
| 13 | dotenv.config(); |
| 14 | |
| 15 | const app = express(); |
| 16 | const PORT = process.env.PORT || 3001; |
| 17 | |
| 18 | // setup middlewares |
| 19 | app.use(cors(corsOptions())); |
| 20 | app.use(helmet()); |
| 21 | |
| 22 | // parse JSON bodies |
| 23 | app.use(express.json({ limit: "10mb" })); |
| 24 | app.use(express.urlencoded({ extended: true })); |
| 25 | |
| 26 | // API routes |
| 27 | app.use("/auth", authRoutes); |
| 28 | app.get("/health", healthCheck); |
| 29 | |
| 30 | // Error handling middleware |
| 31 | app.use(errorHandler); |
| 32 | |
| 33 | app.listen(PORT, () => { |
| 34 | console.log(`Auth service is running on port ${PORT}`); |
| 35 | console.log(`Environment: ${process.env.NODE_ENV}`); |
| 36 | console.log(`Health check: http://localhost:${PORT}/health`); |
| 37 | }); |
| 38 | |
| 39 | export default app; |