Files
explore/nextjs/utils/logRequestFromBot.ts
tom goriunovandGitHub b6d5268188 Enhance OG tags with API data (#1806)
* simple fetch data for token instance page

* generate enhanced metadata

* group query params in page props

* make base gSSP function generic

* add metric for search engine bots

* measure api request duration

* get API data for token, address and dapp pages

* improve typings for apiData prop

* add ENV variable

* tweak logs for /media-type requests

* [skip ci] add prefix to default metrics
2024-04-16 10:27:47 +02:00

29 lines
735 B
TypeScript

import type { IncomingMessage, ServerResponse } from 'http';
import metrics from 'lib/monitoring/metrics';
import detectBotRequest from './detectBotRequest';
export default async function logRequestFromBot(req: IncomingMessage | undefined, res: ServerResponse<IncomingMessage> | undefined, pathname: string) {
if (!req || !res || !metrics) {
return;
}
const botInfo = detectBotRequest(req);
if (!botInfo) {
return;
}
switch (botInfo.type) {
case 'search_engine': {
metrics.searchEngineBotRequests.inc({ route: pathname, bot: botInfo.bot });
return;
}
case 'social_preview': {
metrics.socialPreviewBotRequests.inc({ route: pathname, bot: botInfo.bot });
return;
}
}
}