Remove modify-response middleware (it's huge and redundant) (#266)

Remove custom types and now redundant express middlware.
This commit is contained in:
Alex van Andel 2023-05-19 20:00:04 +02:00 committed by GitHub
parent b7e65e31d6
commit 39a7a2240f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 25 deletions

View File

@ -11,6 +11,32 @@ module.exports = withAxiom({
"@calcom/prisma",
"@calcom/trpc",
],
async headers() {
return [
{
source: "/docs",
headers: [
{
key: "Access-Control-Allow-Credentials",
value: "true",
},
{
key: "Access-Control-Allow-Origin",
value: "*",
},
{
key: "Access-Control-Allow-Methods",
value: "GET, OPTIONS, PATCH, DELETE, POST, PUT",
},
{
key: "Access-Control-Allow-Headers",
value:
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, api_key, Authorization",
},
],
},
];
},
async rewrites() {
return {
afterFiles: [

View File

@ -36,11 +36,10 @@
"@sentry/nextjs": "^7.20.0",
"bcryptjs": "^2.4.3",
"memory-cache": "^0.2.0",
"modify-response-middleware": "^1.1.0",
"next": "~13.2.1",
"next-api-middleware": "^1.0.1",
"next-axiom": "^0.16.0",
"next-swagger-doc": "^0.3.4",
"next-swagger-doc": "^0.3.6",
"next-validations": "^0.2.0",
"typescript": "^4.9.4",
"tzdata": "^1.0.30",

View File

@ -1,6 +1,3 @@
import modifyRes from "modify-response-middleware";
import type { NextApiRequest, NextApiResponse } from "next";
import { use } from "next-api-middleware";
import { withSwagger } from "next-swagger-doc";
import pjson from "~/package.json";
@ -129,22 +126,4 @@ const swaggerHandler = withSwagger({
apiFolder: "pages/api",
});
export default use(
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);
// HACK: This is a hack to fix the swagger-ui issue with the extra channels property.
delete parsed.channels;
return Buffer.from(JSON.stringify(parsed));
}
})
)(swaggerHandler());
export default swaggerHandler();

1
types.d.ts vendored
View File

@ -1 +0,0 @@
declare module "modify-response-middleware";