Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

commit

Vasek Mlejnsky770376322789
diff --git a/api-service/cf-worker-template/index.js b/api-service/cf-worker-template/index.js
index d89fcd338..708551e92 100644
--- a/api-service/cf-worker-template/index.js
+++ b/api-service/cf-worker-template/index.js
@@ -2,20 +2,27 @@ import { Router } from 'itty-router'
const router = Router()
-async function handlegetRequest(request, env) {
- const responseBody = {
- API_KEY: env.API_KEY,
- ANOTHER_KEY: env.ANOTHER_KEY
- }
-
- return new Response(JSON.stringify(responseBody), {
- headers: {
- 'Content-Type': 'application/json'
+async function handlepostRequest(request, env) {
+ const body = await request.json()
+ const email = body.email
+ console.log('email', email)
+ if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
+ return new Response(JSON.stringify({
+ error: 'Invalid email'
+ }), {
+ status: 400
+ })
}
- })
+ const db = new Supabase.DB(env.SUPABASE_URL)
+ await db.query('INSERT INTO users (email) VALUES ($1)', [email])
+ return new Response(JSON.stringify({
+ message: 'Ok'
+ }), {
+ status: 200
+ })
}
-router.get('/', handlegetRequest)
+router.post('/', handlepostRequest)
router.get('*', () => new Response('Not found', { status: 404 }))
export default {
diff --git a/api-service/cf-worker-template/wrangler.toml b/api-service/cf-worker-template/wrangler.toml
index 7dce32b15..6c5f044b7 100644
--- a/api-service/cf-worker-template/wrangler.toml
+++ b/api-service/cf-worker-template/wrangler.toml
@@ -1,12 +1,10 @@
# This wrangler file will be injected withl values during runtime and saved as wrangler.toml
-name = "meteo"
+name = "460355b3"
main = "./index.js"
# route = ''
compatibility_date = "2022-05-03"
send_metrics = false
[vars]
-API_KEY = "1234"
-ANOTHER_KEY = "ABCD"