🐛 Fix api doc CORS
This commit is contained in:
@ -70,6 +70,7 @@
|
||||
"minio": "7.0.32",
|
||||
"next": "13.0.5",
|
||||
"next-auth": "4.12.3",
|
||||
"nextjs-cors": "^2.1.2",
|
||||
"nodemailer": "6.8.0",
|
||||
"nprogress": "0.2.0",
|
||||
"papaparse": "5.3.2",
|
||||
@ -109,14 +110,14 @@
|
||||
"@types/tinycolor2": "1.4.3",
|
||||
"db": "workspace:*",
|
||||
"dotenv": "16.0.3",
|
||||
"eslint": "8.28.0",
|
||||
"eslint-config-custom": "workspace:*",
|
||||
"models": "workspace:*",
|
||||
"next-transpile-modules": "10.0.0",
|
||||
"superjson": "^1.11.0",
|
||||
"tsconfig": "workspace:*",
|
||||
"typescript": "4.9.3",
|
||||
"utils": "workspace:*",
|
||||
"zod": "3.19.1",
|
||||
"eslint": "8.28.0",
|
||||
"eslint-config-custom": "workspace:*"
|
||||
"zod": "3.19.1"
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ export const createWorkspaceProcedure = authenticatedProcedure
|
||||
},
|
||||
},
|
||||
select: { name: true },
|
||||
})) satisfies Pick<Workspace, 'name'>[]
|
||||
})) as Pick<Workspace, 'name'>[]
|
||||
|
||||
if (existingWorkspaceNames.some((workspace) => workspace.name === name))
|
||||
throw new TRPCError({
|
||||
@ -48,7 +48,7 @@ export const createWorkspaceProcedure = authenticatedProcedure
|
||||
members: { create: [{ role: 'ADMIN', userId: user.id }] },
|
||||
plan,
|
||||
},
|
||||
})) satisfies Workspace
|
||||
})) as Workspace
|
||||
|
||||
return {
|
||||
workspace: newWorkspace,
|
||||
|
@ -27,7 +27,7 @@ export const getWorkspaceProcedure = authenticatedProcedure
|
||||
.query(async ({ input: { workspaceId }, ctx: { user } }) => {
|
||||
const workspace = (await prisma.workspace.findFirst({
|
||||
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
||||
})) satisfies Workspace | null
|
||||
})) as Workspace | null
|
||||
|
||||
if (!workspace)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
||||
|
@ -31,7 +31,7 @@ export const listInvitationsInWorkspaceProcedure = authenticatedProcedure
|
||||
workspace: { members: { some: { userId: user.id } } },
|
||||
},
|
||||
select: { createdAt: true, email: true, type: true },
|
||||
})) satisfies WorkspaceInvitation[]
|
||||
})) as WorkspaceInvitation[]
|
||||
|
||||
if (!invitations)
|
||||
throw new TRPCError({
|
||||
|
@ -28,7 +28,7 @@ export const listMembersInWorkspaceProcedure = authenticatedProcedure
|
||||
const members = (await prisma.memberInWorkspace.findMany({
|
||||
where: { userId: user.id, workspaceId },
|
||||
include: { user: { select: { name: true, email: true, image: true } } },
|
||||
})) satisfies WorkspaceMember[]
|
||||
})) as WorkspaceMember[]
|
||||
|
||||
if (!members)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No members found' })
|
||||
|
@ -26,7 +26,7 @@ export const listWorkspacesProcedure = authenticatedProcedure
|
||||
const workspaces = (await prisma.workspace.findMany({
|
||||
where: { members: { some: { userId: user.id } } },
|
||||
select: { name: true, id: true, icon: true, plan: true },
|
||||
})) satisfies Pick<Workspace, 'id' | 'name' | 'icon' | 'plan'>[]
|
||||
})) as Pick<Workspace, 'id' | 'name' | 'icon' | 'plan'>[]
|
||||
|
||||
if (!workspaces)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No workspaces found' })
|
||||
|
@ -34,7 +34,7 @@ export const updateWorkspaceProcedure = authenticatedProcedure
|
||||
|
||||
const workspace = (await prisma.workspace.findFirst({
|
||||
where: { members: { some: { userId: user.id } }, id: workspaceId },
|
||||
})) satisfies Workspace | null
|
||||
})) as Workspace | null
|
||||
|
||||
if (!workspace)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Workspace not found' })
|
||||
|
@ -11,10 +11,7 @@ const prismaGlobal = global as typeof global & {
|
||||
const prisma: PrismaClient =
|
||||
prismaGlobal.prisma ||
|
||||
new PrismaClient({
|
||||
log:
|
||||
process.env.NODE_ENV === 'development'
|
||||
? ['query', 'error', 'warn']
|
||||
: ['error'],
|
||||
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
|
@ -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
|
||||
|
@ -13,6 +13,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/nextjs": "7.21.1",
|
||||
"@trpc/server": "10.3.0",
|
||||
"aws-sdk": "2.1261.0",
|
||||
"bot-engine": "workspace:*",
|
||||
"cors": "2.8.5",
|
||||
@ -21,14 +22,14 @@
|
||||
"google-spreadsheet": "3.3.0",
|
||||
"got": "12.5.3",
|
||||
"next": "13.0.5",
|
||||
"nextjs-cors": "^2.1.2",
|
||||
"nodemailer": "6.8.0",
|
||||
"qs": "6.11.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"sanitize-html": "2.7.3",
|
||||
"stripe": "11.1.0",
|
||||
"trpc-openapi": "1.0.0-alpha.4",
|
||||
"@trpc/server": "10.3.0"
|
||||
"trpc-openapi": "1.0.0-alpha.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "7.20.2",
|
||||
@ -51,10 +52,10 @@
|
||||
"next-transpile-modules": "10.0.0",
|
||||
"node-fetch": "^3.3.0",
|
||||
"papaparse": "5.3.2",
|
||||
"superjson": "^1.11.0",
|
||||
"tsconfig": "workspace:*",
|
||||
"typescript": "4.9.3",
|
||||
"zod": "3.19.1",
|
||||
"superjson": "^1.11.0",
|
||||
"utils": "workspace:*"
|
||||
"utils": "workspace:*",
|
||||
"zod": "3.19.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
import { appRouter } from '@/utils/server/routers/v1/_app'
|
||||
import { captureException } from '@sentry/nextjs'
|
||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||
import cors from 'nextjs-cors'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
export default createOpenApiNextHandler({
|
||||
router: appRouter,
|
||||
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: appRouter,
|
||||
onError({ error }) {
|
||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||
captureException(error)
|
||||
console.error('Something went wrong', error)
|
||||
}
|
||||
},
|
||||
})(req, res)
|
||||
}
|
||||
export default handler
|
||||
|
13
pnpm-lock.yaml
generated
13
pnpm-lock.yaml
generated
@ -94,6 +94,7 @@ importers:
|
||||
next: 13.0.5
|
||||
next-auth: 4.12.3
|
||||
next-transpile-modules: 10.0.0
|
||||
nextjs-cors: ^2.1.2
|
||||
nodemailer: 6.8.0
|
||||
nprogress: 0.2.0
|
||||
papaparse: 5.3.2
|
||||
@ -177,6 +178,7 @@ importers:
|
||||
minio: 7.0.32
|
||||
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||
next-auth: 4.12.3_2xoejpawkzgot77rbv5mbik6ve
|
||||
nextjs-cors: 2.1.2_next@13.0.5
|
||||
nodemailer: 6.8.0
|
||||
nprogress: 0.2.0
|
||||
papaparse: 5.3.2
|
||||
@ -363,6 +365,7 @@ importers:
|
||||
models: workspace:*
|
||||
next: 13.0.5
|
||||
next-transpile-modules: 10.0.0
|
||||
nextjs-cors: ^2.1.2
|
||||
node-fetch: ^3.3.0
|
||||
nodemailer: 6.8.0
|
||||
papaparse: 5.3.2
|
||||
@ -388,6 +391,7 @@ importers:
|
||||
google-spreadsheet: 3.3.0
|
||||
got: 12.5.3
|
||||
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||
nextjs-cors: 2.1.2_next@13.0.5
|
||||
nodemailer: 6.8.0
|
||||
qs: 6.11.0
|
||||
react: 18.2.0
|
||||
@ -13924,6 +13928,15 @@ packages:
|
||||
- babel-plugin-macros
|
||||
dev: false
|
||||
|
||||
/nextjs-cors/2.1.2_next@13.0.5:
|
||||
resolution: {integrity: sha512-2yOVivaaf2ILe4f/qY32hnj3oC77VCOsUQJQfhVMGsXE/YMEWUY2zy78sH9FKUCM7eG42/l3pDofIzMD781XGA==}
|
||||
peerDependencies:
|
||||
next: ^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0
|
||||
dependencies:
|
||||
cors: 2.8.5
|
||||
next: 13.0.5_mqvh5p7ejg4taogoj6tpk3gd5a
|
||||
dev: false
|
||||
|
||||
/no-case/2.3.2:
|
||||
resolution: {integrity: sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==}
|
||||
dependencies:
|
||||
|
Reference in New Issue
Block a user