Skip to content

Commit 75ab75e

Browse files
authored
I think...fix the prod api (#89)
1 parent e41da61 commit 75ab75e

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/index.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createYoga } from "graphql-yoga";
2-
import { useCSRFPrevention } from "@graphql-yoga/plugin-csrf-prevention";
1+
import { createYoga, maskError } from "graphql-yoga";
32
import { useMaskedErrors } from "@envelop/core";
43
import { APP_ENV } from "~/env";
54
import { useImmediateIntrospection } from "@envelop/immediate-introspection";
@@ -90,19 +89,27 @@ export const yoga = createYoga<Env>({
9089
: `{}`,
9190
};
9291
},
93-
// cors: {
94-
// origin: ["*"],
95-
// credentials: true,
96-
// methods: ["POST", "GET", "OPTIONS"],
97-
// },
92+
cors: (request) => {
93+
const requestOrigin = request.headers.get("origin") ?? undefined;
94+
return {
95+
origin: requestOrigin,
96+
credentials: true,
97+
allowedHeaders: ["*"],
98+
methods: ["POST", "GET", "OPTIONS"],
99+
};
100+
},
98101
schema,
99102
logging: "debug",
100103
plugins: [
101-
// APP_ENV === "production" &&
102-
// useCSRFPrevention({
103-
// requestHeaders: ["x-graphql-csrf-token"],
104-
// }),
105-
APP_ENV === "production" && useMaskedErrors(),
104+
APP_ENV === "production" &&
105+
useMaskedErrors({
106+
errorMessage: "Internal Server Error",
107+
maskError: (error, message) => {
108+
// eslint-disable-next-line no-console
109+
console.error("ERROR", error);
110+
return maskError(error, message);
111+
},
112+
}),
106113
useImmediateIntrospection(),
107114
(APP_ENV === "production" || APP_ENV === "staging") &&
108115
useOpenTelemetry(

0 commit comments

Comments
 (0)