middleware.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { NextResponse } from 'next/server';
  2. const redirectRules = {
  3. '/umi': {
  4. '/web3js-adapters': '/umi/web3js-differences-and-adapters',
  5. '/web3js-differences': '/umi/web3js-differences-and-adapters',
  6. '/connecting-to-umi': '/umi/getting-started',
  7. },
  8. '/toolbox': {
  9. '/': '/umi/toolbox',
  10. '/getting-started': '/umi/toolbox',
  11. },
  12. '/guides': {
  13. '/javascript/how-to-create-an-spl-token-on-solana':
  14. '/guides/javascript/how-to-create-a-solana-token',
  15. },
  16. '/bubblegum': {
  17. '/getting-started': '/bubblegum/sdk',
  18. '/getting-started/js': '/bubblegum/sdk/javascript',
  19. '/getting-started/rust': '/bubblegum/sdk/rust',
  20. },
  21. '/core': {
  22. '/getting-started': '/core/sdk',
  23. 'guides/javascript/how-to-create-a-core-nft-asset':
  24. '/core/guides/javascript/how-to-create-a-core-nft-asset-with-javascript',
  25. },
  26. '/core-candy-machine': {
  27. '/getting-started': '/core-candy-machine/sdk',
  28. '/getting-started/js': '/core-candy-machine/sdk/javascript',
  29. '/getting-started/rust': '/core-candy-machine/sdk/rust',
  30. },
  31. '/mpl-hybrid': {
  32. 'guides/mpl-404-hyrbid-ui-template':
  33. '/mpl-hybrid/guides/mpl-404-hybrid-ui-template',
  34. },
  35. '/aura': {
  36. '/api/v1/das/get-asset': '/das-api/methods/get-asset',
  37. '/api/v1/das/get-asset-batch': '/das-api/methods/get-assets',
  38. '/api/v1/das/get-asset-proof': '/das-api/methods/get-asset-proof',
  39. '/api/v1/das/get-asset-proof-batch': '/das-api/methods/get-asset-proofs',
  40. '/api/v1/das/get-assets-by-owner': '/das-api/methods/get-assets-by-owner',
  41. '/api/v1/das/get-assets-by-authority': '/das-api/methods/get-assets-by-authority',
  42. '/api/v1/das/get-assets-by-creator': '/das-api/methods/get-assets-by-creator',
  43. '/api/v1/das/get-assets-by-group': '/das-api/methods/get-assets-by-group',
  44. '/api/v1/das/get-signatures-for-asset': '/das-api/methods/get-asset-signatures',
  45. '/api/v1/das/search-assets': '/das-api/methods/search-assets',
  46. },
  47. }
  48. export function middleware(request) {
  49. const { pathname } = request.nextUrl
  50. for (const [rootPath, rule] of Object.entries(redirectRules)) {
  51. if (pathname.startsWith(rootPath)) {
  52. if (typeof rule === 'string') {
  53. // Direct redirect
  54. return NextResponse.redirect(new URL(rule, request.url), 308)
  55. } else if (typeof rule === 'object') {
  56. // Nested redirects
  57. const subPath = pathname.slice(rootPath.length) || '/'
  58. const destination = rule[subPath]
  59. if (destination) {
  60. return NextResponse.redirect(new URL(destination, request.url), 308)
  61. }
  62. }
  63. }
  64. }
  65. return NextResponse.next()
  66. }
  67. export const config = {
  68. matcher: [
  69. '/umi/:path*',
  70. '/toolbox/:path*',
  71. '/core/:path*',
  72. '/mpl-hybrid/:path*',
  73. '/guides/javascript/how-to-create-an-spl-token-on-solana',
  74. '/core-candy-machine/:path*',
  75. '/bubblegum/:path*',
  76. '/aura/:path*',
  77. ],
  78. }