Skip to content

Commit

Permalink
refactor: move request logger middleware to express level
Browse files Browse the repository at this point in the history
  • Loading branch information
rackstar committed Jan 7, 2025
1 parent 7b4a406 commit 5b20a47
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const main = async () => {
next();
});

// log incoming requests
app.use((req, res, next) => {
console.info(`${req.method} ${req.originalUrl}`);
next();
});

// initiate routes
app.use('/v2', capacityRouter);
app.use('/v2', quoteRouter);
Expand Down
5 changes: 1 addition & 4 deletions src/routes/capacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { inspect } = require('node:util');
const { ethers, BigNumber } = require('ethers');
const express = require('express');

const { requestLogger } = require('./middleware');
const {
getAllProductCapacities,
getProductCapacity,
Expand All @@ -13,10 +12,8 @@ const {
const { SECONDS_PER_DAY } = require('../lib/constants');
const { asyncRoute } = require('../lib/helpers');

const { formatUnits } = ethers.utils;

const router = express.Router();
router.use(requestLogger);
const { formatUnits } = ethers.utils;

const formatCapacityResult = capacity => ({
productId: capacity.productId,
Expand Down
22 changes: 0 additions & 22 deletions src/routes/middleware.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/routes/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ const { inspect } = require('node:util');

const express = require('express');

const { requestLogger } = require('./middleware');
const { asyncRoute } = require('../lib/helpers');
const { pricingEngine } = require('../lib/pricingEngine');

const router = express.Router();
router.use(requestLogger);

const formatPricingResult = pricing => ({
productId: pricing.productId,
Expand Down
5 changes: 1 addition & 4 deletions src/routes/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ const { inspect } = require('node:util');
const { BigNumber, ethers } = require('ethers');
const express = require('express');

const { requestLogger } = require('./middleware');
const { TARGET_PRICE_DENOMINATOR } = require('../lib/constants');
const { asyncRoute } = require('../lib/helpers');
const { quoteEngine } = require('../lib/quoteEngine');
const { selectAsset } = require('../store/selectors');

const { Zero } = ethers.constants;

const router = express.Router();
router.use(requestLogger);
const { Zero } = ethers.constants;

/**
* @openapi
Expand Down

0 comments on commit 5b20a47

Please sign in to comment.