@hvedinich/utils 0.0.71 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hvedinich/utils",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "description": "utils module",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 (this.originDomains?.length) {
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 ? authHeader.includes('x-with-credentials') : false;
67
+ const wantsCredentials = authHeader
68
+ ? authHeader.includes('x-with-credentials') || authHeader.includes('authorization')
69
+ : false;
62
70
  const corsOptions = {
63
- origin: wantsCredentials ? this.originDomains : '*',
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: !this.originDomains?.length });
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' }));
@@ -25,6 +25,9 @@ const ctxToHeaders = ctx => {
25
25
  if (ctx.permission) {
26
26
  result['x-yoda-permission'] = ctx.permission.join(',');
27
27
  }
28
+ if (ctx?.headers) {
29
+ result.headers = JSON.stringify(ctx.headers);
30
+ }
28
31
  return result;
29
32
  };
30
33