Skip to content

Commit

Permalink
feat: rewrite url to shorten collection name
Browse files Browse the repository at this point in the history
  • Loading branch information
MartianGreed committed Sep 16, 2024
1 parent 0dc5fd4 commit 036a99e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
18 changes: 11 additions & 7 deletions apps/arkmarket/src/app/token/[contractAddress]/[tokenId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions apps/arkmarket/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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])
}

0 comments on commit 036a99e

Please sign in to comment.