From a0ea88b2ddcbb6ae285c4ee368e63fb6f65e02c7 Mon Sep 17 00:00:00 2001 From: MrUnknownDE Date: Fri, 2 Jan 2026 18:00:00 +0100 Subject: [PATCH] feat: add MAC address lookup API endpoint and backend dependencies --- backend/package.json | 2 +- backend/routes/macLookup.js | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/package.json b/backend/package.json index e0ed97f..5cb1706 100644 --- a/backend/package.json +++ b/backend/package.json @@ -23,4 +23,4 @@ "qs": "^6.14.1", "whois-json": "^2.0.4" } -} +} \ No newline at end of file diff --git a/backend/routes/macLookup.js b/backend/routes/macLookup.js index 3d19281..da2e706 100644 --- a/backend/routes/macLookup.js +++ b/backend/routes/macLookup.js @@ -1,6 +1,5 @@ const express = require('express'); const Sentry = require("@sentry/node"); -const oui = require('oui'); const pino = require('pino'); const { isValidMacAddress } = require('../utils'); @@ -21,10 +20,12 @@ router.get('/', async (req, res) => { // Use 'oui' library to find vendor try { + // Dynamic import for ESM-only 'oui' module + const ouiModule = await import('oui'); + const oui = ouiModule.default; + const ouiData = oui(mac); // oui returns a string (Vendor Name) or null if not found - // Sometimes it returns an object? The documentation says it returns the organization name string. - // Let's handle both just in case, but usually it's a string or null. let vendor = null; if (ouiData) { @@ -38,15 +39,11 @@ router.get('/', async (req, res) => { logger.info({ requestIp, mac }, 'MAC address not found in OUI database'); res.status(404).json({ success: false, error: 'Vendor not found for this MAC address.' }); } - } catch (err) { - // oui might throw on invalid input, though we validated it. - throw err; + } catch (error) { + logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed'); + Sentry.captureException(error, { extra: { requestIp, mac } }); + res.status(500).json({ success: false, error: 'An unexpected error occurred during the MAC lookup.' }); } -} catch (error) { - logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed'); - Sentry.captureException(error, { extra: { requestIp, mac } }); - res.status(500).json({ success: false, error: 'An unexpected error occurred during the MAC lookup.' }); -} }); module.exports = router; \ No newline at end of file