Skip to content

Commit

Permalink
Added connection logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Jan 18, 2025
1 parent 0e4f4af commit b355522
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/api/send.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { isbot } from 'isbot';
import { NextApiRequest, NextApiResponse } from 'next';
import {
Expand Down Expand Up @@ -85,6 +86,16 @@ const schema = {
export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
await useCors(req, res);

req.socket.on('close', () => {
console.log('Client closed connection');
});

const abortController = new AbortController();
req.on('close', () => {
console.log('Request closed');
abortController.abort();
});

if (req.method === 'POST') {
if (!process.env.DISABLE_BOT_CHECK && isbot(req.headers['user-agent'])) {
return ok(res, { beep: 'boop' });
Expand Down

0 comments on commit b355522

Please sign in to comment.