Skip to content

Commit

Permalink
test: skip turnstile verification
Browse files Browse the repository at this point in the history
  • Loading branch information
ngshiheng committed Oct 6, 2022
1 parent da45b99 commit d5ef6cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.vscode
dist
node_modules
worker
test.js
worker
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const options = {

let shortenLink

const BASE_URL = 'https://atomic-url-staging.jerrynsh.workers.dev/'
const BASE_URL = __ENV.TEST_URL
const DUMMY_ORIGINAL_URL = 'https://jerrynsh.com/i-built-my-own-tiny-url/'

export default function () {
Expand Down
7 changes: 6 additions & 1 deletion src/middleware/turnstile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ Turnstile is Cloudflare's smart CAPTCHA alternative.
A middleware that calls Cloudflare's siteverify endpoint to validate the Turnstile widget response.
Do note to set `TURNSTILE_SECRET` accordingly.
Do note to set `TURNSTILE_SECRET` and `TEST_URL` accordingly.
*/
export const turnstileMiddleware = async (request) => {
/* eslint-disable no-undef */
if (request.url == TEST_URL) {
console.log('Skipping Turnstile verification for tests.')
return
}

const { turnstileToken } = await request.clone().json()

const response = await fetch(TURNSTILE_SITEVERIFY_ENDPOINT, {
Expand Down

0 comments on commit d5ef6cf

Please sign in to comment.