UNPKG

myex-cli

Version:

Opinionated Express.js framework with CLI tools

112 lines (107 loc) 3.01 kB
import express from 'express'; import { authMiddleware } from '../middlewares/auth.middleware.js'; const router = express.Router(); /** * @swagger * /api: * get: * summary: Get API information * tags: [System] * responses: * 200: * description: API information * content: * application/json: * schema: * type: object * properties: * message: * type: string * example: Welcome to the API * version: * type: string * example: 1.0.0 * endpoints: * type: object * properties: * auth: * type: string * example: /api/auth * users: * type: string * example: /api/users */ router.get('/', (req, res) => { res.json({ message: 'Welcome to the API', version: '1.0.0', endpoints: { auth: '/api/auth', users: '/api/users', // Add more endpoints as they become available }, }); }); /** * @swagger * /api/protected: * get: * summary: Example of a protected route * tags: [System] * security: * - BearerAuth: [] * responses: * 200: * description: Protected route info * content: * application/json: * schema: * type: object * properties: * message: * type: string * example: This is a protected route * user: * type: object * properties: * id: * type: string * example: 60d21b4667d0d8992e610c85 * email: * type: string * example: john@example.com * role: * type: string * example: user * 401: * $ref: '#/components/responses/UnauthorizedError' */ router.get('/protected', authMiddleware.authenticateToken, (req, res) => { res.json({ message: 'This is a protected route', user: req.user, }); }); /** * @swagger * /health: * get: * summary: Check API health * tags: [System] * responses: * 200: * description: API health status * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: UP * timestamp: * type: string * format: date-time */ // Note: This route is actually defined in /src/routes/index.js but documented here for completeness export const apiRoutes = router;