Skip to content

Commit

Permalink
trying another method of making activity requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed Dec 26, 2024
1 parent fb6ae4d commit aaa5fd0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
20 changes: 3 additions & 17 deletions .github/workflows/activity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,11 @@ name: Supabase Activity
on:
schedule:
- cron: "0 9 * * 1,4"
workflow_dispatch:

jobs:
send-http-request:
name: Execute Supabase Update
runs-on: ubuntu-latest
steps:
- name: Send PATCH request
run: |
date=$(date -u +'%Y-%m-%dT%H:%M:%S.%3NZ')
response=$(curl -s -o /dev/null -w "%{http_code}" \
-X PATCH "${{ secrets.SUPABASE_URL }}/rest/v1/keep-alive?id=eq.1" \
-H "apikey: ${{ secrets.SUPABASE_ANON_KEY }}" \
-H "Authorization: Bearer ${{ secrets.SUPABASE_ANON_KEY }}" \
-H "Content-Type: application/json" \
-H "Prefer: return=minimal" \
-d "{\"value\": \"$date\"}")
if [ "$response" -eq 204 ]; then
echo "Success! $date"
else
echo "Failed with status code: $response"
exit 1
fi
- name: Send HTTP Request
run: curl https://trophy-hunt.vercel.app/api/activity
19 changes: 19 additions & 0 deletions app/api/activity/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createClient } from "@/utils/supabase/server";
import { cookies } from "next/headers";

const email = process.env.NEXT_PUBLIC_KEEP_ALIVE_USER ?? "";
const password = process.env.NEXT_PUBLIC_KEEP_ALIVE_PASSWORD ?? "";

export const GET = async (): Promise<Response> => {
try {
const sb = createClient(cookies());
const payload = { email, password };
const { error } = await sb.auth.signInWithPassword(payload);
const date = new Date().toISOString();
if (error != null) throw new Error(error.message);
return Response.json(`Success! ${date}`);
} catch (error) {
const message = (error as Error).message ?? "An error occurred.";
return Response.json(message, { status: 400 });
}
};

0 comments on commit aaa5fd0

Please sign in to comment.