diff --git a/src/index.js b/src/index.js index defa44f..c64d4af 100644 --- a/src/index.js +++ b/src/index.js @@ -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); diff --git a/src/routes/capacity.js b/src/routes/capacity.js index 3034652..7a58067 100644 --- a/src/routes/capacity.js +++ b/src/routes/capacity.js @@ -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, @@ -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, diff --git a/src/routes/middleware.js b/src/routes/middleware.js deleted file mode 100644 index 731cd45..0000000 --- a/src/routes/middleware.js +++ /dev/null @@ -1,22 +0,0 @@ -const { inspect } = require('node:util'); - -/** - * Request Logger Middleware - * - * Logs incoming requests with method, URL, params, and query. - * - * @param {import('express').Request} req - The Express request object - * @param {import('express').Response} res - The Express response object - * @param {Function} next - The next middleware function - */ -const requestLogger = (req, res, next) => { - const params = Object.keys(req.params).length ? `\nparams: ${inspect(req.params, { depth: null })}` : ''; - const query = Object.keys(req.query).length ? `\nquery: ${inspect(req.query, { depth: null })}` : ''; - - console.info(`${req.method} ${req.baseUrl}${req.route?.path || req.path}${params}${query}`); - next(); -}; - -module.exports = { - requestLogger, -}; diff --git a/src/routes/pricing.js b/src/routes/pricing.js index 0bbb73d..0e69be0 100644 --- a/src/routes/pricing.js +++ b/src/routes/pricing.js @@ -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, diff --git a/src/routes/quote.js b/src/routes/quote.js index 483bed8..204c591 100644 --- a/src/routes/quote.js +++ b/src/routes/quote.js @@ -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