mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-26 18:38:39 -06:00
feat: env to hide index and manager
This commit is contained in:
parent
cd0da914f4
commit
d9629157dd
@ -3,7 +3,13 @@ import { readFileSync } from 'fs';
|
|||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
|
export type HttpServer = {
|
||||||
|
TYPE: 'http' | 'https';
|
||||||
|
PORT: number;
|
||||||
|
URL: string;
|
||||||
|
HIDE_INDEX: boolean;
|
||||||
|
HIDE_MANAGER: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
|
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
|
||||||
export type Cors = {
|
export type Cors = {
|
||||||
@ -173,6 +179,8 @@ export class ConfigService {
|
|||||||
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
|
TYPE: process.env.SERVER_TYPE as 'http' | 'https',
|
||||||
PORT: Number.parseInt(process.env.SERVER_PORT) || 8080,
|
PORT: Number.parseInt(process.env.SERVER_PORT) || 8080,
|
||||||
URL: process.env.SERVER_URL,
|
URL: process.env.SERVER_URL,
|
||||||
|
HIDE_INDEX: process.env?.SERVER_HIDE_INDEX === 'true',
|
||||||
|
HIDE_MANAGER: process.env?.SERVER_HIDE_MANAGER === 'true',
|
||||||
},
|
},
|
||||||
CORS: {
|
CORS: {
|
||||||
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
|
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],
|
||||||
|
@ -9,6 +9,8 @@ SERVER:
|
|||||||
TYPE: http # https
|
TYPE: http # https
|
||||||
PORT: 8080 # 443
|
PORT: 8080 # 443
|
||||||
URL: localhost
|
URL: localhost
|
||||||
|
HIDE_INDEX: false
|
||||||
|
HIDE_MANAGER: false
|
||||||
|
|
||||||
CORS:
|
CORS:
|
||||||
ORIGIN:
|
ORIGIN:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
import { Auth, configService } from '../../config/env.config';
|
import { Auth, configService, HttpServer } from '../../config/env.config';
|
||||||
import { authGuard } from '../guards/auth.guard';
|
import { authGuard } from '../guards/auth.guard';
|
||||||
import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard';
|
import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard';
|
||||||
import { ChamaaiRouter } from './chamaai.router';
|
import { ChamaaiRouter } from './chamaai.router';
|
||||||
@ -30,19 +30,27 @@ enum HttpStatus {
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
|
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
|
||||||
|
const httpServer = configService.get<HttpServer>('SERVER');
|
||||||
|
|
||||||
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
|
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
|
||||||
|
|
||||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
|
|
||||||
router
|
// Hide index if needed
|
||||||
.get('/', (req, res) => {
|
|
||||||
|
if (!httpServer.HIDE_INDEX)
|
||||||
|
router.get('/', (req, res) => {
|
||||||
res.status(HttpStatus.OK).json({
|
res.status(HttpStatus.OK).json({
|
||||||
status: HttpStatus.OK,
|
status: HttpStatus.OK,
|
||||||
message: 'Welcome to the Evolution API, it is working!',
|
message: 'Welcome to the Evolution API, it is working!',
|
||||||
version: packageJson.version,
|
version: packageJson.version,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
.use('/instance', new InstanceRouter(configService, ...guards).router)
|
|
||||||
|
// Hide manager if needed
|
||||||
|
if (!httpServer.HIDE_MANAGER) router.use('/manager', new ViewsRouter().router);
|
||||||
|
|
||||||
|
router
|
||||||
.use('/manager', new ViewsRouter().router)
|
.use('/manager', new ViewsRouter().router)
|
||||||
.use('/message', new MessageRouter(...guards).router)
|
.use('/message', new MessageRouter(...guards).router)
|
||||||
.use('/chat', new ChatRouter(...guards).router)
|
.use('/chat', new ChatRouter(...guards).router)
|
||||||
|
Loading…
Reference in New Issue
Block a user