From da45b99c05498aed0a1226ecbd16e21d2deef79d Mon Sep 17 00:00:00 2001 From: Jerry Ng Date: Wed, 5 Oct 2022 23:52:39 +0800 Subject: [PATCH 1/2] feat: add Cloudflare Turnstile to site --- src/handlers/createShortUrl.js | 2 +- src/handlers/redirectShortUrl.js | 2 +- src/index.html | 51 ++++++++++++++++++++++---------- src/index.js | 5 ++-- src/middleware/shortUrlCache.js | 4 +-- src/middleware/turnstile.js | 24 +++++++++++++++ 6 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 src/middleware/turnstile.js diff --git a/src/handlers/createShortUrl.js b/src/handlers/createShortUrl.js index b526927..6dfc835 100644 --- a/src/handlers/createShortUrl.js +++ b/src/handlers/createShortUrl.js @@ -54,6 +54,6 @@ export const createShortUrl = async (request, event) => { return response } catch (error) { console.error(error, error.stack) - return new Response('Unexpected Error', { status: 500 }) + return new Response('Internal Server Error', { status: 500 }) } } diff --git a/src/handlers/redirectShortUrl.js b/src/handlers/redirectShortUrl.js index 0d5d74d..cab2102 100644 --- a/src/handlers/redirectShortUrl.js +++ b/src/handlers/redirectShortUrl.js @@ -16,5 +16,5 @@ export const redirectShortUrl = async ({ params }) => { if (originalUrl) { return Response.redirect(originalUrl, 301) } - return new Response(NOT_FOUND_PAGE, { headers: { 'content-type': 'text/html;charset=UTF-8' } }) + return new Response(NOT_FOUND_PAGE, { headers: { 'Content-Type': 'text/html;charset=UTF-8' }, status: 404 }) } diff --git a/src/index.html b/src/index.html index 2dba6da..939dc38 100644 --- a/src/index.html +++ b/src/index.html @@ -14,10 +14,25 @@ +