2
0

🐛 Fix api doc CORS

This commit is contained in:
Baptiste Arnaud
2022-11-30 16:27:32 +01:00
parent 3c8820b212
commit 94a57aea21
12 changed files with 68 additions and 38 deletions

View File

@ -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