Skip to content

Commit

Permalink
Merge pull request #86 from escottalexander/refine-etl
Browse files Browse the repository at this point in the history
Change path for function in vercel.json, add authorization to ETL endpoint
  • Loading branch information
escottalexander authored Jul 22, 2024
2 parents 5245f52 + 548b39b commit 25f98ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/nextjs/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ OSO_GRAPHQL_ENDPOINT=
OSO_API_KEY=
AGORA_API_ENDPOINT=https://vote.optimism.io/api_v1
AGORA_API_KEY=
# Secret to prevent unauthorized calls to the ETL
CRON_SECRET=
# Don't let the ETL be called more than every X milliseconds
ETL_WINDOW_MS=85500000 # 23 hours and 45 minutes
# Days prior to check existance when running ETL
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/pages/api/etl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (req.method !== "GET") {
return res.status(405).json({ message: "Method not allowed." });
}
if (process.env.CRON_SECRET && req.headers?.authorization !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).end("Unauthorized");
}
try {
const mongooseConnection = await dbConnect();
// Log the ETL process
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/vercel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"functions": {
"src/app/pages/api/etl/*": {
"app/pages/api/etl/*": {
"maxDuration": 300
}
},
Expand Down

0 comments on commit 25f98ad

Please sign in to comment.