mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* 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
29 lines
735 B
TypeScript
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;
|
|
}
|
|
}
|
|
}
|