From 1703976a4f5bf39191c06a86404775448fd7fb86 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Mon, 2 May 2022 11:30:08 +0530 Subject: [PATCH] Fix docs request --- package.json | 1 + pages/api/docs.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 18d9081665..91eca0e3cc 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "private": true, "scripts": { "dev": "next build && PORT=3002 next start", + "dev-real":"PORT=3002 next dev", "start": "PORT=3002 next start", "build": "next build", "lint": "next lint", diff --git a/pages/api/docs.ts b/pages/api/docs.ts index dd544e89ae..943c6b9f25 100644 --- a/pages/api/docs.ts +++ b/pages/api/docs.ts @@ -29,7 +29,16 @@ const swaggerHandler = withSwagger({ }); export default use( - modifyRes((content: string, _req: NextApiRequest, _res: NextApiResponse) => { + modifyRes((content: string, _req: NextApiRequest, res: NextApiResponse) => { + // Add all headers here instead of next.config.js as it is throwing error( Cannot set headers after they are sent to the client) for OPTIONS method + // It is known to happen only in Dev Mode. + res.setHeader("Access-Control-Allow-Credentials", "true"); + res.setHeader("Access-Control-Allow-Origin", "*"); + res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS, PATCH, DELETE, POST, PUT"); + res.setHeader( + "Access-Control-Allow-Headers", + "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, api_key, Authorization" + ); if (content) { const parsed = JSON.parse(content); delete parsed.channels;