Skip to content

Commit 9363301

Browse files
Add DISABLE_DOCS and DISABLE_MANAGER
1 parent 42ae7d1 commit 9363301

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/config/env.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { readFileSync } from 'fs';
33
import { load } from 'js-yaml';
44
import { join } from 'path';
55

6-
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
6+
export type HttpServer = {
7+
TYPE: 'http' | 'https';
8+
PORT: number;
9+
URL: string;
10+
DISABLE_DOCS: boolean;
11+
DISABLE_MANAGER: boolean;
12+
};
713

814
export type HttpMethods = 'POST' | 'GET' | 'PUT' | 'DELETE';
915
export type Cors = {
@@ -186,6 +192,8 @@ export class ConfigService {
186192
TYPE: (process.env.SERVER_TYPE as 'http' | 'https') || 'http',
187193
PORT: Number.parseInt(process.env.SERVER_PORT) || 8080,
188194
URL: process.env.SERVER_URL,
195+
DISABLE_DOCS: process.env?.SERVER_DISABLE_DOCS === 'true',
196+
DISABLE_MANAGER: process.env?.SERVER_DISABLE_MANAGER === 'true',
189197
},
190198
CORS: {
191199
ORIGIN: process.env.CORS_ORIGIN.split(',') || ['*'],

src/dev-env.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ SERVER:
99
TYPE: http # https
1010
PORT: 8080 # 443
1111
URL: localhost
12+
DISABLE_MANAGER: false
13+
DISABLE_DOCS: false
14+
1215

1316
CORS:
1417
ORIGIN:

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function bootstrap() {
5353
app.use('/store', express.static(join(ROOT_DIR, 'store')));
5454

5555
app.use('/', router);
56-
app.use(swaggerRouter);
56+
57+
if (!configService.get('SERVER').DISABLE_DOCS) app.use(swaggerRouter);
5758

5859
app.use(
5960
(err: Error, req: Request, res: Response, next: NextFunction) => {

src/whatsapp/routers/index.router.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ enum HttpStatus {
3131

3232
const router = Router();
3333
const authType = configService.get<Auth>('AUTHENTICATION').TYPE;
34+
const serverConfig = configService.get('SERVER');
3435
const guards = [instanceExistsGuard, instanceLoggedGuard, authGuard[authType]];
3536

3637
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
3738

39+
if (!serverConfig.DISABLE_MANAGER) router.use('/manager', new ViewsRouter().router);
40+
3841
router
3942
.get('/', (req, res) => {
4043
res.status(HttpStatus.OK).json({
4144
status: HttpStatus.OK,
4245
message: 'Welcome to the Evolution API, it is working!',
4346
version: packageJson.version,
44-
swagger: `${req.protocol}://${req.get('host')}/docs`,
47+
swagger: !serverConfig.DISABLE_DOCS ? `${req.protocol}://${req.get('host')}/docs` : undefined,
48+
manager: !serverConfig.DISABLE_MANAGER ? `${req.protocol}://${req.get('host')}/manager` : undefined,
4549
documentation: `https://doc.evolution-api.com`,
46-
manager: `${req.protocol}://${req.get('host')}/manager`,
4750
});
4851
})
4952
.use('/instance', new InstanceRouter(configService, ...guards).router)
50-
.use('/manager', new ViewsRouter().router)
5153
.use('/message', new MessageRouter(...guards).router)
5254
.use('/chat', new ChatRouter(...guards).router)
5355
.use('/group', new GroupRouter(...guards).router)

0 commit comments

Comments
 (0)