@dcl/platform-server-commons
Version:
Platform's Http Server Common utils
27 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ethAddressNormalizerMiddleware = void 0;
const schemas_1 = require("@dcl/schemas");
/**
* Middleware that automatically converts Ethereum addresses to lowercase in URL parameters
* This middleware detects parameters that match the Ethereum address pattern and normalizes them
*/
function ethAddressNormalizerMiddleware() {
return async function (ctx, next) {
if (!ctx.params || typeof ctx.params !== 'object') {
return await next();
}
// Check each parameter to see if it's an Ethereum address
for (const [key, value] of Object.entries(ctx.params)) {
// Ensure the value is a string before validation and conversion
if (typeof value === 'string' && schemas_1.EthAddress.validate(value)) {
// Convert to lowercase if it's an Ethereum address
ctx.params[key] = value.toLowerCase();
}
}
// Call the next middleware/handler with the normalized context
return await next();
};
}
exports.ethAddressNormalizerMiddleware = ethAddressNormalizerMiddleware;
//# sourceMappingURL=eth-address-normalizer-middleware.js.map