2023-03-15 11:51:30 +01:00
|
|
|
import { createContext } from '@/helpers/server/context'
|
2023-10-07 12:03:42 +02:00
|
|
|
import * as Sentry from '@sentry/nextjs'
|
2022-11-30 16:27:32 +01:00
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
2022-11-18 18:21:40 +01:00
|
|
|
import { createOpenApiNextHandler } from 'trpc-openapi'
|
2022-11-30 16:27:32 +01:00
|
|
|
import cors from 'nextjs-cors'
|
2023-11-23 12:05:31 +01:00
|
|
|
import { publicRouter } from '@/helpers/server/routers/publicRouter'
|
2022-11-18 18:21:40 +01:00
|
|
|
|
2022-11-30 16:27:32 +01:00
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
|
|
|
await cors(req, res, {
|
2023-01-11 14:57:58 +01:00
|
|
|
origin: ['https://docs.typebot.io', 'http://localhost:3000'],
|
2022-11-30 16:27:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return createOpenApiNextHandler({
|
2023-11-23 12:05:31 +01:00
|
|
|
router: publicRouter,
|
2022-11-30 16:27:32 +01:00
|
|
|
createContext,
|
|
|
|
|
onError({ error }) {
|
|
|
|
|
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
2023-10-07 12:03:42 +02:00
|
|
|
Sentry.captureException(error)
|
2022-11-30 16:27:32 +01:00
|
|
|
console.error('Something went wrong', error)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})(req, res)
|
|
|
|
|
}
|
2023-11-26 11:12:13 +01:00
|
|
|
|
|
|
|
|
export const config = {
|
|
|
|
|
api: {
|
|
|
|
|
bodyParser: {
|
|
|
|
|
sizeLimit: '4mb',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 16:27:32 +01:00
|
|
|
export default handler
|