backend-manager 4.0.25 → 4.0.27

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": "backend-manager",
3
- "version": "4.0.25",
3
+ "version": "4.0.27",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -45,25 +45,43 @@ function BackendAssistant() {
45
45
  return self;
46
46
  }
47
47
 
48
- function tryUrl(req) {
48
+ function tryUrl(self) {
49
+ const req = self.ref.req;
50
+ const Manager = self.Manager;
51
+ const projectType = Manager?.options?.projectType;
52
+
49
53
  try {
50
- return `${req.protocol}://${req.get('host')}${req.originalUrl}`
54
+ const protocol = req.protocol;
55
+ const host = req.get('host');
56
+ const forwardedHost = req.get('x-forwarded-host');
57
+ const path = req.path;
58
+
59
+ // Like this becuse "req.originalUrl" does NOT have path for all cases (like when calling https://us-central1-{id}.cloudfunctions.net/giftImport)
60
+ if (projectType === 'firebase') {
61
+ return forwardedHost
62
+ ? `${protocol}://${forwardedHost}${path}`
63
+ : `${protocol}://${host}${path}`;
64
+ }
51
65
  } catch {
52
66
  return '';
53
67
  }
54
68
  }
55
69
 
56
70
  function tryParse(input) {
57
- var ret;
71
+ var parsed;
58
72
 
73
+ // Try to require JSON5
59
74
  JSON5 = JSON5 || require('json5');
60
75
 
76
+ // Try to parse
61
77
  try {
62
- ret = JSON5.parse(input);
78
+ parsed = JSON5.parse(input);
63
79
  } catch (e) {
64
- ret = input
80
+ parsed = input
65
81
  }
66
- return ret;
82
+
83
+ // Return
84
+ return parsed;
67
85
  }
68
86
 
69
87
  BackendAssistant.prototype.init = function (ref, options) {
@@ -186,7 +204,7 @@ BackendAssistant.prototype.init = function (ref, options) {
186
204
  } else {
187
205
  self.request.type = 'form';
188
206
  }
189
- self.request.url = tryUrl(self.ref.req);
207
+ self.request.url = tryUrl(self);
190
208
  self.request.path = self.ref.req.path || '';
191
209
  self.request.user = self.resolveAccount({authenticated: false});
192
210