Skip to content

Commit 22d7b9a

Browse files
committed
directus & turnstile
1 parent 6197108 commit 22d7b9a

21 files changed

+17262
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
.env
3+
/node_modules

70-directus-gcp/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
.env

70-directus-gcp/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:16-alpine
2+
3+
WORKDIR /src
4+
5+
ADD . /src
6+
7+
RUN npm install --production
8+
9+
EXPOSE 8055
10+
11+
CMD ["npm", "start"]

70-directus-gcp/package-lock.json

+12,769
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

70-directus-gcp/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "cms-directus-youtube",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "directus start"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"@directus/drive-gcs": "^9.21.2",
15+
"directus": "^10.4.2",
16+
"pg": "^8.11.1"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts
36+
37+
.env
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
18+
19+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export async function POST(request: Request) {
4+
const { token } = await request.json();
5+
const secret = process.env.TURNSTILE_SECRET_KEY;
6+
const ip = request.headers.get('x-forwarded-for');
7+
8+
if (!secret || !ip || !token) {
9+
return NextResponse.json(
10+
{ error: 'Missing required parameters' },
11+
{ status: 400 }
12+
);
13+
}
14+
15+
// Validate the token by calling the
16+
// "/siteverify" API endpoint.
17+
let formData = new FormData();
18+
formData.append('secret', secret);
19+
formData.append('response', token);
20+
formData.append('remoteip', ip);
21+
22+
const url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
23+
const result = await fetch(url, {
24+
body: formData,
25+
method: 'POST',
26+
});
27+
28+
const { success } = await result.json();
29+
30+
return NextResponse.json({ success });
31+
}
25.3 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
input {
6+
@apply border border-gray-300 rounded-md shadow-sm;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import './globals.css'
2+
import type { Metadata } from 'next'
3+
import { Inter } from 'next/font/google'
4+
5+
const inter = Inter({ subsets: ['latin'] })
6+
7+
export const metadata: Metadata = {
8+
title: 'Create Next App',
9+
description: 'Generated by create next app',
10+
}
11+
12+
export default function RootLayout({
13+
children,
14+
}: {
15+
children: React.ReactNode
16+
}) {
17+
return (
18+
<html lang="en">
19+
<body className={inter.className}>{children}</body>
20+
</html>
21+
)
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use client';
2+
import Script from 'next/script';
3+
4+
declare global {
5+
interface Window {
6+
turnstile: any;
7+
}
8+
}
9+
10+
export default function Home() {
11+
const submitHandler = async (e: any) => {
12+
e.preventDefault();
13+
14+
const token = window.turnstile.getResponse();
15+
16+
const serverValidation = await fetch('/api/cf', {
17+
method: 'POST',
18+
headers: {
19+
'Content-Type': 'application/json',
20+
},
21+
body: JSON.stringify({ token }),
22+
});
23+
24+
const { success } = await serverValidation.json();
25+
26+
if (success) {
27+
// continue el form submission...
28+
alert('Eres humano. Formulario enviado');
29+
} else {
30+
window.turnstile.reset();
31+
alert('Intenta de nuevo');
32+
}
33+
};
34+
return (
35+
<>
36+
<Script
37+
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
38+
async
39+
defer
40+
></Script>
41+
<main className="flex flex-col justify-center items-center w-screen h-screen">
42+
<form onSubmit={submitHandler} method="POST" className="flex flex-col">
43+
<input type="text" placeholder="username" />
44+
<input type="password" placeholder="password" />
45+
46+
<button type="submit" value="Submit">
47+
Log in
48+
</button>
49+
50+
<div
51+
className="cf-turnstile"
52+
data-sitekey="0x4AAAAAAAHS-Hx_bt9HbsKH"
53+
data-callback="javascriptCallback"
54+
data-theme="light"
55+
data-language="es"
56+
></div>
57+
</form>
58+
</main>
59+
</>
60+
);
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {}
3+
4+
module.exports = nextConfig

0 commit comments

Comments
 (0)