diff --git a/src/backend/Logger.ts b/src/backend/Logger.ts index 2338ce01..948beaa6 100644 --- a/src/backend/Logger.ts +++ b/src/backend/Logger.ts @@ -30,7 +30,7 @@ export const winstonSettings = { exitOnError: false }; -type logFN = (...args: (string | number)[]) => {}; +export type logFN = (...args: (string | number)[]) => {}; export const Logger: { error: logFN, diff --git a/src/backend/middlewares/RenderingMWs.ts b/src/backend/middlewares/RenderingMWs.ts index 6d5da82d..8d68fecd 100644 --- a/src/backend/middlewares/RenderingMWs.ts +++ b/src/backend/middlewares/RenderingMWs.ts @@ -7,6 +7,7 @@ import {NotificationManager} from '../model/NotifocationManager'; import {Logger} from '../Logger'; import {SharingDTO} from '../../common/entities/SharingDTO'; import {Utils} from '../../common/Utils'; +import {LoggerRouter} from '../routes/LoggerRouter'; export class RenderingMWs { @@ -92,6 +93,7 @@ export class RenderingMWs { if (err instanceof ErrorDTO) { if (err.details) { Logger.warn('Handled error:'); + LoggerRouter.log(Logger.warn, req, res); console.log(err); delete (err.details); // do not send back error object to the client side @@ -103,7 +105,7 @@ export class RenderingMWs { const message = new Message(err, null); return res.json(message); } - NotificationManager.error('unknown server error', err); + NotificationManager.error('Unknown server error', err); return next(err); } diff --git a/src/backend/routes/LoggerRouter.ts b/src/backend/routes/LoggerRouter.ts index a5d3c4bf..f6c32303 100644 --- a/src/backend/routes/LoggerRouter.ts +++ b/src/backend/routes/LoggerRouter.ts @@ -1,5 +1,5 @@ import {Express, NextFunction, Request, Response} from 'express'; -import {Logger} from '../Logger'; +import {logFN, Logger} from '../Logger'; declare global { namespace Express { @@ -14,43 +14,34 @@ declare global { * Adds logging to express */ export class LoggerRouter { + public static log(loggerFn: logFN, req: Request, res: Response) { + if (req.logged === true) { + return; + } + req.logged = true; + req._startTime = Date.now(); + const end = res.end; + res.end = (a?: any, b?: any, c?: any) => { + res.end = end; + res.end(a, b, c); + loggerFn(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms'); + }; + } + public static route(app: Express) { app.get('/api*', (req: Request, res: Response, next: NextFunction) => { - req._startTime = Date.now(); - req.logged = true; - const end = res.end; - res.end = (a?: any, b?: any, c?: any) => { - res.end = end; - res.end(a, b, c); - Logger.verbose(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms'); - }; + LoggerRouter.log(Logger.verbose, req, res); return next(); }); app.get('/node_modules*', (req: Request, res: Response, next: NextFunction) => { - req._startTime = Date.now(); - req.logged = true; - const end = res.end; - res.end = (a?: any, b?: any, c?: any) => { - res.end = end; - res.end(a, b, c); - Logger.silly(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms'); - }; + LoggerRouter.log(Logger.silly, req, res); return next(); }); app.use((req: Request, res: Response, next: NextFunction) => { - if (req.logged === true) { - return next(); - } - req._startTime = Date.now(); - const end = res.end; - res.end = (a?: any, b?: any, c?: any) => { - res.end = end; - res.end(a, b, c); - Logger.debug(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms'); - }; + LoggerRouter.log(Logger.debug, req, res); return next(); }); diff --git a/src/frontend/app/ui/settings/share/share.settings.service.ts b/src/frontend/app/ui/settings/share/share.settings.service.ts index c4f5d6b1..be6bcafa 100644 --- a/src/frontend/app/ui/settings/share/share.settings.service.ts +++ b/src/frontend/app/ui/settings/share/share.settings.service.ts @@ -26,6 +26,9 @@ export class ShareSettingsService extends AbstractSettingsService { + if (!this._settingsService.settings.value.Client.Sharing.enabled) { + return Promise.resolve([]); + } return this._networkService.getJson('/share/list'); }