|
1 | | -import { createYoga } from "graphql-yoga"; |
2 | | -import { useCSRFPrevention } from "@graphql-yoga/plugin-csrf-prevention"; |
| 1 | +import { createYoga, maskError } from "graphql-yoga"; |
3 | 2 | import { useMaskedErrors } from "@envelop/core"; |
4 | 3 | import { APP_ENV } from "~/env"; |
5 | 4 | import { useImmediateIntrospection } from "@envelop/immediate-introspection"; |
@@ -90,19 +89,27 @@ export const yoga = createYoga<Env>({ |
90 | 89 | : `{}`, |
91 | 90 | }; |
92 | 91 | }, |
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 | + }, |
98 | 101 | schema, |
99 | 102 | logging: "debug", |
100 | 103 | 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 | + }), |
106 | 113 | useImmediateIntrospection(), |
107 | 114 | (APP_ENV === "production" || APP_ENV === "staging") && |
108 | 115 | useOpenTelemetry( |
|
0 commit comments