new(all): Web log.
This commit is contained in:
parent
baad3e7563
commit
2a83e1e631
3 changed files with 593 additions and 1124 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -19,3 +19,6 @@
|
||||||
*.env
|
*.env
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.wwebjs_auth
|
.wwebjs_auth
|
||||||
|
GB.log
|
||||||
|
gb.log
|
||||||
|
GB.log.json
|
||||||
|
|
1686
package-lock.json
generated
1686
package-lock.json
generated
File diff suppressed because it is too large
Load diff
24
src/app.ts
24
src/app.ts
|
@ -52,6 +52,7 @@ import { GBCoreService } from '../packages/core.gbapp/services/GBCoreService';
|
||||||
import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer';
|
import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer';
|
||||||
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService';
|
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService';
|
||||||
import { GBMinService } from '../packages/core.gbapp/services/GBMinService';
|
import { GBMinService } from '../packages/core.gbapp/services/GBMinService';
|
||||||
|
var auth = require('basic-auth');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,6 +110,7 @@ export class GBServer {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
GBLog.info(`Now accepting connections on ${port}...`);
|
GBLog.info(`Now accepting connections on ${port}...`);
|
||||||
|
|
||||||
// Reads basic configuration, initialize minimal services.
|
// Reads basic configuration, initialize minimal services.
|
||||||
|
@ -196,6 +198,28 @@ export class GBServer {
|
||||||
GBServer.globals.minService = minService;
|
GBServer.globals.minService = minService;
|
||||||
await minService.buildMin(instances);
|
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...`);
|
GBLog.info(`The Bot Server is in RUNNING mode...`);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue