-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx-dev): move supabase analytics to edge
- Loading branch information
Showing
6 changed files
with
71 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { checkEnvVariables } from '@nx/nx-dev/util-ai'; | ||
import { SupabaseClient, createClient } from '@supabase/supabase-js'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
const supabaseUrl = process.env['NX_NEXT_PUBLIC_SUPABASE_URL']; | ||
const supabaseServiceKey = process.env['NX_SUPABASE_SERVICE_ROLE_KEY_ACTUAL']; | ||
export const config = { | ||
runtime: 'edge', | ||
}; | ||
|
||
export default async function handler(request: NextRequest) { | ||
checkEnvVariables('not-needed', supabaseUrl, supabaseServiceKey); | ||
const { table, analyticsData } = await request.json(); | ||
|
||
const supabaseClient: SupabaseClient<any, 'public', any> = createClient( | ||
supabaseUrl as string, | ||
supabaseServiceKey as string | ||
); | ||
|
||
try { | ||
const result = await supabaseClient.from(table).insert(analyticsData); | ||
|
||
return new Response(JSON.stringify(result), { | ||
status: 200, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
} catch (e) { | ||
return new Response( | ||
JSON.stringify({ | ||
error: 'Error saving feedback in Supabase.', | ||
}), | ||
{ | ||
status: 500, | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters