new(all): Web log.

This commit is contained in:
Rodrigo Rodriguez 2022-08-06 19:38:13 -03:00
parent baad3e7563
commit 2a83e1e631
3 changed files with 593 additions and 1124 deletions

5
.gitignore vendored
View file

@ -18,4 +18,7 @@
.env
*.env
.vscode/launch.json
.wwebjs_auth
.wwebjs_auth
GB.log
gb.log
GB.log.json

1688
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -52,6 +52,7 @@ import { GBCoreService } from '../packages/core.gbapp/services/GBCoreService';
import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer';
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService';
import { GBMinService } from '../packages/core.gbapp/services/GBMinService';
var auth = require('basic-auth');
/**
@ -109,6 +110,7 @@ export class GBServer {
(async () => {
try {
GBLog.info(`Now accepting connections on ${port}...`);
// Reads basic configuration, initialize minimal services.
@ -196,6 +198,28 @@ export class GBServer {
GBServer.globals.minService = minService;
await minService.buildMin(instances);
if (process.env.ENABLE_WEBLOG) {
var admins = {
'admin': { password: process.env.ADMIN_PASS },
};
// ... some not authenticated middlewares
server.use((req, res, next) => {
var user = auth(req);
if (!user || !admins[user.name] || admins[user.name].password !== user.pass) {
res.set('WWW-Authenticate', 'Basic realm="example"');
return res.status(401).send();
}
return next();
});
// If global log enabled, reorders transports adding web logging.
const loggers = GBLog.getLogger();
require('winston-logs-display')(server, loggers[1]);
}
GBLog.info(`The Bot Server is in RUNNING mode...`);