@hvedinich/utils 0.0.72 → 0.0.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/index.js +13 -5
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -51,16 +51,24 @@ const defaultContext = async ({ req }) => {
|
|
|
51
51
|
class Server {
|
|
52
52
|
constructor({ config, healthCheck, context, originDomains }) {
|
|
53
53
|
this.config = config;
|
|
54
|
-
this.originDomains = originDomains;
|
|
55
54
|
this.app = express();
|
|
55
|
+
this.activateApolloCors = !originDomains?.length;
|
|
56
56
|
this.router = null;
|
|
57
57
|
this.app.get('/_status', healthCheck || defaultCHealthCheck);
|
|
58
|
-
if (
|
|
58
|
+
if (originDomains?.length) {
|
|
59
59
|
this.app.use((req, res, next) => {
|
|
60
|
+
if (req.url !== '/graphql') {
|
|
61
|
+
this.activateApolloCors = true;
|
|
62
|
+
next();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.activateApolloCors = false;
|
|
60
66
|
const authHeader = req.headers['access-control-request-headers'];
|
|
61
|
-
const wantsCredentials = authHeader
|
|
67
|
+
const wantsCredentials = authHeader
|
|
68
|
+
? authHeader.includes('x-with-credentials') || authHeader.includes('authorization')
|
|
69
|
+
: false;
|
|
62
70
|
const corsOptions = {
|
|
63
|
-
origin: wantsCredentials ?
|
|
71
|
+
origin: wantsCredentials ? originDomains : '*',
|
|
64
72
|
credentials: wantsCredentials,
|
|
65
73
|
};
|
|
66
74
|
|
|
@@ -116,7 +124,7 @@ class Server {
|
|
|
116
124
|
const server = new ApolloServer(serverOptions);
|
|
117
125
|
|
|
118
126
|
const bodyParserConfig = this.jsonLimit ? { limit: this.jsonLimit } : true;
|
|
119
|
-
server.applyMiddleware({ app: this.app, path: '/graphql', bodyParserConfig, cors:
|
|
127
|
+
server.applyMiddleware({ app: this.app, path: '/graphql', bodyParserConfig, cors: this.activateApolloCors });
|
|
120
128
|
|
|
121
129
|
if (this.config.playground) {
|
|
122
130
|
this.app.get('/playground', expressPlayground({ endpoint: '/graphql', subscriptionEndpoint: '/subscriptions' }));
|