-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move all remaining pages/ api routes to app/
- Move all pages/ api routes to app/ - Use edge runtime for these routes - Misc changes
- Loading branch information
Showing
12 changed files
with
100 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { RateLimiters, checkActiveSessionEdge, checkRateLimitAllowedEdge } from 'lib/api/auth'; | ||
import { covalentEventGetter, etherscanEventGetter, nodeEventGetter } from 'lib/api/globals'; | ||
import { isCovalentSupportedChain, isEtherscanSupportedChain, isNodeSupportedChain } from 'lib/utils/chains'; | ||
import { parseErrorMessage } from 'lib/utils/errors'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
interface Props { | ||
params: { | ||
chainId: string; | ||
}; | ||
} | ||
|
||
export const runtime = 'edge'; | ||
export const preferredRegion = ['iad1']; | ||
|
||
export async function POST(req: NextRequest, { params }: Props) { | ||
if (!(await checkActiveSessionEdge(req))) { | ||
return new Response(JSON.stringify({ message: 'No API session is active' }), { status: 403 }); | ||
} | ||
|
||
if (!(await checkRateLimitAllowedEdge(req, RateLimiters.LOGS))) { | ||
return new Response(JSON.stringify({ message: 'Too many requests, please try again later.' }), { status: 429 }); | ||
} | ||
|
||
const chainId = Number.parseInt(params.chainId, 10); | ||
const body = await req.json(); | ||
|
||
try { | ||
if (isCovalentSupportedChain(chainId)) { | ||
const events = await covalentEventGetter.getEvents(chainId, body); | ||
return new Response(JSON.stringify(events), { status: 200 }); | ||
} | ||
|
||
if (isEtherscanSupportedChain(chainId)) { | ||
const events = await etherscanEventGetter.getEvents(chainId, body); | ||
return new Response(JSON.stringify(events), { status: 200 }); | ||
} | ||
|
||
if (isNodeSupportedChain(chainId)) { | ||
const events = await nodeEventGetter.getEvents(chainId, body); | ||
return new Response(JSON.stringify(events), { status: 200 }); | ||
} | ||
} catch (e) { | ||
console.error('Error occurred', parseErrorMessage(e)); | ||
return new Response(JSON.stringify({ message: parseErrorMessage(e) }), { status: 500 }); | ||
} | ||
|
||
return new Response(JSON.stringify({ message: `Chain with ID ${chainId} is unsupported` }), { status: 404 }); | ||
} |
File renamed without changes.
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,10 @@ | ||
import { storeSessionEdge } from 'lib/api/auth'; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
export async function POST(req: NextRequest) { | ||
const res = new NextResponse(JSON.stringify({ ok: true }), { status: 200 }); | ||
await storeSessionEdge(req, res); | ||
return res; | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.