#NextJS API route to Astro API endpoint

5 messages · Page 1 of 1 (latest)

autumn marsh
#

Hello there ! I am trying to self-host the TinaCMS backend, in their documention example they use NextJS API routes:

// pages/api/tina/[...routes].{ts,js}

import { TinaNodeBackend, LocalBackendAuthentication } from '@tinacms/datalayer'
import { TinaAuthJSOptions, AuthJsBackendAuthentication } from 'tinacms-authjs'

import databaseClient from '../../../tina/__generated__/databaseClient'

const isLocal = process.env.TINA_PUBLIC_IS_LOCAL === 'true'

const handler = TinaNodeBackend({
  authentication: isLocal
    ? LocalBackendAuthentication()
    : AuthJsBackendAuthentication({
        authOptions: TinaAuthJSOptions({
          databaseClient: databaseClient,
          secret: process.env.NEXTAUTH_SECRET,
        }),
      }),
  databaseClient,
})

export default (req: NextApiRequest, res: NextApiResponse<ResponseData>) => {
  // Modify the request here if you need to
  return handler(req, res)
}

As you can see, I don't have much control on what the handler function does with the response and the request, is there a reliable way to 'convert' Astro's APIContext to NextApiRequest and NextApiResponse<ResponseData> ?

Tina

1. Choose a Git provider, database adapter, and auth provider You will need to choose a Git provider, database adapter, and auth provider. You can use any of the providers we have created, or you…

crystal saffron
#

unfortunately, astro's api routes are designed in a way that it works the same across node and edge runtimes

#

node-specific code can't automatically be used here

autumn marsh
crystal saffron
#

oh wow that's impressive!