Skip to content

Commit

Permalink
Merge pull request #1481 from myrotvorets/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
myrotvorets-team authored Mar 20, 2024
2 parents 168ace4 + 6f0fe5a commit 5795fd1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 77 deletions.
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
"@cloudnative/health-connect": "^2.1.0",
"@myrotvorets/express-async-middleware-wrapper": "^2.2.0",
"@myrotvorets/express-microservice-middlewares": "^3.1.0",
"@myrotvorets/express-otel-middlewares": "^1.1.0",
"@myrotvorets/express-request-logger": "^1.2.1",
"@myrotvorets/oav-installer": "^5.0.0",
"@myrotvorets/opentelemetry-configurator": "^7.6.0",
"@myrotvorets/opentelemetry-plugin-knex": "^0.31.0",
"@myrotvorets/otel-utils": "^1.2.0",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/core": "^1.22.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"awilix": "^10.0.1",
"envalid": "^8.0.0",
"express": "^4.18.3",
Expand Down
42 changes: 0 additions & 42 deletions src/middleware/duration.mts

This file was deleted.

26 changes: 0 additions & 26 deletions src/middleware/logger.mts

This file was deleted.

21 changes: 16 additions & 5 deletions src/server.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import express, { type Express } from 'express';
import express, { type Express, type Request, type Response } from 'express';
import { installOpenApiValidator } from '@myrotvorets/oav-installer';
import { errorMiddleware, notFoundMiddleware } from '@myrotvorets/express-microservice-middlewares';
import { createServer, getTracer, recordErrorToSpan } from '@myrotvorets/otel-utils';
import {
LoggerFromRequestFunction,
requestDurationMiddleware,
requestLoggerMiddleware,
} from '@myrotvorets/express-otel-middlewares';

import { initializeContainer, scopedContainerMiddleware } from './lib/container.mjs';
import { requestDurationMiddleware } from './middleware/duration.mjs';
import { loggerMiddleware } from './middleware/logger.mjs';
import { LocalsWithContainer, initializeContainer, scopedContainerMiddleware } from './lib/container.mjs';

import { searchController } from './controllers/search.mjs';
import { monitoringController } from './controllers/monitoring.mjs';
import { requestDurationHistogram } from './lib/metrics.mjs';

const loggerFromRequest: LoggerFromRequestFunction = (req: Request) =>
(req.res as Response<never, LocalsWithContainer> | undefined)?.locals.container.resolve('logger');

export function configureApp(app: Express): ReturnType<typeof initializeContainer> {
return getTracer().startActiveSpan('configureApp', (span): ReturnType<typeof initializeContainer> => {
Expand All @@ -20,7 +27,11 @@ export function configureApp(app: Express): ReturnType<typeof initializeContaine
const base = dirname(fileURLToPath(import.meta.url));
const db = container.resolve('db');

app.use(requestDurationMiddleware, scopedContainerMiddleware, loggerMiddleware);
app.use(
requestDurationMiddleware(requestDurationHistogram),
scopedContainerMiddleware,
requestLoggerMiddleware('dzhura', loggerFromRequest),
);
app.use('/monitoring', monitoringController(db));

app.use(
Expand Down

0 comments on commit 5795fd1

Please sign in to comment.