From 0c1cfb1ac521df2fabfc0141552d333f750fa964 Mon Sep 17 00:00:00 2001 From: Foxix Date: Fri, 3 Jan 2025 19:58:01 +0000 Subject: [PATCH] Update 2 files - /src/public/api-docs/index.html - /src/index.js --- src/index.js | 25 ++++++++++++++++--------- src/public/api-docs/index.html | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index be6c8c5..db098cd 100644 --- a/src/index.js +++ b/src/index.js @@ -200,13 +200,20 @@ const swaggerOptions = { } } }, - apis: ['./src/routes/*.js', './src/index.js'], + apis: [path.join(__dirname, 'routes', '*.js'), path.join(__dirname, 'index.js')] }; const swaggerDocs = swaggerJsdoc(swaggerOptions); +// CORS configuration +app.use(cors({ + origin: '*', + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization'], + credentials: true +})); + // Middleware -app.use(cors()); app.use(express.json()); app.use(express.static(path.join(__dirname, 'public'))); @@ -219,13 +226,17 @@ app.use((req, res, next) => { next(); }); -// Serve Swagger JSON +// API Documentation routes +app.get('/api-docs', (req, res) => { + res.sendFile(path.join(__dirname, 'public', 'api-docs', 'index.html')); +}); + app.get('/api-docs/swagger.json', (req, res) => { res.setHeader('Content-Type', 'application/json'); res.send(swaggerDocs); }); -// Routes +// API routes app.use('/movies', require('./routes/movies')); /** @@ -257,9 +268,5 @@ app.use((err, req, res, next) => { // Start server app.listen(port, () => { console.log(`Server is running on port ${port}`); - console.log(`Documentation available at http://localhost:${port}/api-docs`); -}); - -app.get('/api-docs', (req, res) => { - res.sendFile(path.join(__dirname, 'public', 'index.html')); + console.log(`Documentation available at https://neomovies-api/api-docs`); }); diff --git a/src/public/api-docs/index.html b/src/public/api-docs/index.html index fd7e95d..d8984bb 100644 --- a/src/public/api-docs/index.html +++ b/src/public/api-docs/index.html @@ -37,8 +37,9 @@