mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
Update 3 files
- /package-lock.json - /vercel.json - /src/index.js
This commit is contained in:
3
package-lock.json
generated
3
package-lock.json
generated
@@ -17,6 +17,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^3.0.2"
|
"nodemon": "^3.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@apidevtools/json-schema-ref-parser": {
|
"node_modules/@apidevtools/json-schema-ref-parser": {
|
||||||
|
|||||||
26
src/index.js
26
src/index.js
@@ -3,12 +3,18 @@ const express = require('express');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const swaggerJsdoc = require('swagger-jsdoc');
|
const swaggerJsdoc = require('swagger-jsdoc');
|
||||||
const swaggerUi = require('swagger-ui-express');
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
const path = require('path');
|
||||||
const TMDBClient = require('./config/tmdb');
|
const TMDBClient = require('./config/tmdb');
|
||||||
const healthCheck = require('./utils/health');
|
const healthCheck = require('./utils/health');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
// Определяем базовый URL для документации
|
||||||
|
const BASE_URL = process.env.VERCEL_URL
|
||||||
|
? `https://${process.env.VERCEL_URL}`
|
||||||
|
: `http://localhost:${port}`;
|
||||||
|
|
||||||
// Swagger configuration
|
// Swagger configuration
|
||||||
const swaggerOptions = {
|
const swaggerOptions = {
|
||||||
definition: {
|
definition: {
|
||||||
@@ -24,8 +30,8 @@ const swaggerOptions = {
|
|||||||
},
|
},
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
url: `http://localhost:${port}`,
|
url: BASE_URL,
|
||||||
description: 'Development server',
|
description: process.env.VERCEL_URL ? 'Production server' : 'Development server',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
tags: [
|
tags: [
|
||||||
@@ -204,12 +210,17 @@ const swaggerDocs = swaggerJsdoc(swaggerOptions);
|
|||||||
const swaggerCustomOptions = {
|
const swaggerCustomOptions = {
|
||||||
customCss: '.swagger-ui .topbar { display: none }',
|
customCss: '.swagger-ui .topbar { display: none }',
|
||||||
customSiteTitle: "Neo Movies API Documentation",
|
customSiteTitle: "Neo Movies API Documentation",
|
||||||
customfavIcon: "https://www.themoviedb.org/favicon.ico"
|
customfavIcon: "https://www.themoviedb.org/favicon.ico",
|
||||||
|
swaggerOptions: {
|
||||||
|
url: `${BASE_URL}/api-docs/swagger.json`,
|
||||||
|
persistAuthorization: true
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
// TMDB client middleware
|
// TMDB client middleware
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
@@ -220,8 +231,15 @@ app.use((req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Serve Swagger JSON
|
||||||
|
app.get('/api-docs/swagger.json', (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.send(swaggerDocs);
|
||||||
|
});
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs, swaggerCustomOptions));
|
app.use('/api-docs', swaggerUi.serve);
|
||||||
|
app.get('/api-docs', swaggerUi.setup(null, swaggerCustomOptions));
|
||||||
app.use('/movies', require('./routes/movies'));
|
app.use('/movies', require('./routes/movies'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,9 +7,16 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"routes": [
|
"routes": [
|
||||||
|
{
|
||||||
|
"src": "/api-docs/(.*)",
|
||||||
|
"dest": "src/index.js"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"src": "/(.*)",
|
"src": "/(.*)",
|
||||||
"dest": "src/index.js"
|
"dest": "src/index.js"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"env": {
|
||||||
|
"NODE_ENV": "production"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user