const express = require('express'); const swaggerUi = require('swagger-ui-express'); const swaggerJsdoc = require('swagger-jsdoc'); const jsonServer = require('json-server'); const app = express(); const port = 3001; // different from Angular 4200 const cors = require('cors'); app.use(cors()); // Swagger setup const options = { swaggerDefinition: { openapi: '3.0.0', info: { title: 'Fake API', version: '1.0.0', }, }, apis: ['./swagger.yaml'], // Your API spec }; const swaggerSpec = swaggerJsdoc(options); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); // JSON Server setup const router = jsonServer.router('db.json'); const middlewares = jsonServer.defaults(); app.use('/api', middlewares, router); app.listen(port, () => { console.log(`🚀 Server running at http://localhost:${port}`); console.log(`📚 Swagger docs at http://localhost:${port}/api-docs`); });