🐛 Fix api doc CORS
This commit is contained in:
@ -1,15 +1,24 @@
|
||||
import { createContext } from '@/utils/server/context'
|
||||
import { trpcRouter } from '@/utils/server/routers/v1/trpcRouter'
|
||||
import { captureException } from '@sentry/nextjs'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||
import cors from 'nextjs-cors'
|
||||
|
||||
export default createOpenApiNextHandler({
|
||||
router: trpcRouter,
|
||||
createContext,
|
||||
onError({ error }) {
|
||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||
captureException(error)
|
||||
console.error('Something went wrong', error)
|
||||
}
|
||||
},
|
||||
})
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
await cors(req, res, {
|
||||
origin: 'https://docs.typebot.io',
|
||||
})
|
||||
|
||||
return createOpenApiNextHandler({
|
||||
router: trpcRouter,
|
||||
createContext,
|
||||
onError({ error }) {
|
||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||
captureException(error)
|
||||
console.error('Something went wrong', error)
|
||||
}
|
||||
},
|
||||
})(req, res)
|
||||
}
|
||||
export default handler
|
||||
|
Reference in New Issue
Block a user