45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { All, Controller, HttpCode, HttpStatus, Req } from '@nestjs/common';
|
|
import type { Request } from 'express';
|
|
import { AllowPublicAccess } from '../auth/allow-public-access.decorator';
|
|
|
|
type RiotWebhookRequest = Request & {
|
|
rawBody?: Buffer;
|
|
};
|
|
|
|
@Controller('riot')
|
|
export class RiotWebhookController {
|
|
@All('webhooks/tournament')
|
|
@AllowPublicAccess()
|
|
@HttpCode(HttpStatus.OK)
|
|
public captureTournamentWebhook(@Req() req: RiotWebhookRequest) {
|
|
const receivedAt = new Date().toISOString();
|
|
const rawBodyText = req.rawBody?.toString('utf8') ?? null;
|
|
const body: unknown = req.body;
|
|
const logPayload = {
|
|
receivedAt,
|
|
method: req.method,
|
|
url: req.originalUrl,
|
|
protocol: req.protocol,
|
|
hostname: req.hostname,
|
|
ip: req.ip,
|
|
ips: req.ips,
|
|
headers: req.headers,
|
|
query: req.query,
|
|
params: req.params,
|
|
body,
|
|
rawBodyLength: req.rawBody?.length ?? null,
|
|
rawBodyText,
|
|
};
|
|
|
|
console.log('\n[RIOT TOURNAMENT WEBHOOK] Incoming request');
|
|
console.dir(logPayload, { depth: null });
|
|
console.log('[RIOT TOURNAMENT WEBHOOK] End request log\n');
|
|
|
|
return {
|
|
ok: true,
|
|
message: 'Riot webhook received.',
|
|
receivedAt,
|
|
};
|
|
}
|
|
}
|