feat: add API_DOMAIN environment variable for production configuration

- Add API_DOMAIN env var to set domain/IP for API in production
- Update swagger.config.js to use dynamic server URLs
- Update server.js CORS configuration to use API_DOMAIN
- Update env.example with new API_DOMAIN field
- Add comprehensive documentation in README.md
- Fixes CORS issues in Swagger docs for production deployments
This commit is contained in:
Michilis
2025-07-15 21:45:40 +00:00
parent ba36f96f4c
commit 91259e98c6
4 changed files with 48 additions and 8 deletions

View File

@@ -1,5 +1,11 @@
require('dotenv').config();
const swaggerJsdoc = require('swagger-jsdoc');
// Get the API domain from environment variable, default to localhost:3000
const apiDomain = process.env.API_DOMAIN || 'localhost:3000';
const isProduction = process.env.NODE_ENV === 'production';
const protocol = isProduction ? 'https' : 'http';
const options = {
definition: {
openapi: '3.0.0',
@@ -18,12 +24,8 @@ const options = {
},
servers: [
{
url: 'http://localhost:3000',
description: 'Development server'
},
{
url: 'https://api.example.com',
description: 'Production server'
url: `${protocol}://${apiDomain}`,
description: isProduction ? 'Production server' : 'Development server'
}
],
components: {