diff --git a/apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/page.tsx b/apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/page.tsx index db1b59ec..c763602f 100644 --- a/apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/page.tsx +++ b/apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/page.tsx @@ -22,17 +22,21 @@ interface TokenPageProps { export default async function TokenPage({ params: { contractAddress, tokenId }, }: TokenPageProps) { - const token = await getToken({ - contractAddress, - tokenId, - }); + let token; + try { + token = await getToken({ + contractAddress, + tokenId, + }); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (err) { + return notFound(); + } + const tokenMarketData = await getTokenMarketData({ contractAddress, tokenId, }); - if (!token) { - return notFound(); - } const collection = CollectionDescription[token.collection_address]; if (!collection) { diff --git a/apps/arkmarket/src/middleware.ts b/apps/arkmarket/src/middleware.ts new file mode 100644 index 00000000..7d4b0135 --- /dev/null +++ b/apps/arkmarket/src/middleware.ts @@ -0,0 +1,19 @@ +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' +import type { Collections } from './config/homepage'; +import { ChainId, CollectionAddresses } from './config/homepage'; + +// This function can be marked `async` if using `await` inside +export function middleware(request: NextRequest) { + + // index 0 is the first / at index 1 we got collection name + const splittedPath = request.nextUrl.pathname.split('/') + const collectionName = splittedPath[1] as Collections; + const collectionAddress = CollectionAddresses[collectionName]; + if (undefined === collectionAddress) { + return NextResponse.next() + } + const address = collectionAddress[ChainId.SN_MAIN]; + + return NextResponse.rewrite(request.nextUrl.origin + '/token/' + address + '/' + splittedPath[2]) +}