add blogs, move pictures to local + much more
This commit is contained in:
@@ -3,15 +3,30 @@
|
||||
// This enables autocomplete, go to definition, etc.
|
||||
|
||||
import { serve } from "https://deno.land/std@0.131.0/http/server.ts"
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
||||
|
||||
console.log("Hello from Functions!")
|
||||
console.log("Hello from functions!")
|
||||
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||
|
||||
serve(async (req) => {
|
||||
const { name } = await req.json()
|
||||
const data = {
|
||||
message: `Hello ${name}!`,
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response('ok')
|
||||
}
|
||||
|
||||
const supabase = createClient(Deno.env.get('SUPABASE_URL'), Deno.env.get('SUPABASE_ANON_KEY'))
|
||||
|
||||
const { email, name } = await req.json()
|
||||
if (!name || !email || !emailRegex.test(email)) throw new Error(
|
||||
'Please provide a valid email address or name'
|
||||
)
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('subscribers')
|
||||
.upsert({ name: name, email: email })
|
||||
.select()
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
return new Response(
|
||||
JSON.stringify(data),
|
||||
{ headers: { "Content-Type": "application/json" } },
|
||||
|
||||
Reference in New Issue
Block a user