@reldens/server-utils 0.29.0 → 0.30.0

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.
@@ -97,12 +97,30 @@ class AppServerFactory
97
97
  };
98
98
  }
99
99
 
100
+ parseUrl(url)
101
+ {
102
+ if(!url || 'string' !== typeof url){
103
+ return false;
104
+ }
105
+ let cleanUrl = url.trim();
106
+ if(!cleanUrl.startsWith('http://') && !cleanUrl.startsWith('https://')){
107
+ return false;
108
+ }
109
+ let isHttps = cleanUrl.startsWith('https://');
110
+ let domain = cleanUrl.replace(/^https?:\/\//, '').split(':')[0];
111
+ return {
112
+ isHttps,
113
+ domain,
114
+ protocol: isHttps ? 'https' : 'http'
115
+ };
116
+ }
117
+
100
118
  createAppServer(appServerConfig)
101
119
  {
102
120
  if(appServerConfig){
103
121
  Object.assign(this, appServerConfig);
104
122
  }
105
- this.addHttpDomainsAsDevelopment();
123
+ this.processEnvironmentUrls();
106
124
  this.detectDevelopmentMode();
107
125
  this.setupDevelopmentConfiguration();
108
126
  this.setupProtocolEnforcement();
@@ -124,23 +142,23 @@ class AppServerFactory
124
142
  return {app: this.app, appServer: this.appServer};
125
143
  }
126
144
 
127
- extractDomainFromHttpUrl(url)
145
+ processEnvironmentUrls()
128
146
  {
129
- if(!url || !url.startsWith('http://')){
130
- return false;
131
- }
132
- return url.replace(/^http:\/\//, '').split(':')[0];
133
- }
134
-
135
- addHttpDomainsAsDevelopment()
136
- {
137
- let hostDomain = this.extractDomainFromHttpUrl(process.env.RELDENS_APP_HOST);
138
- let publicDomain = this.extractDomainFromHttpUrl(process.env.RELDENS_PUBLIC_URL);
139
- if(hostDomain && !this.developmentDomains.includes(hostDomain)){
140
- this.developmentDomains.push(hostDomain);
147
+ let publicUrlInfo = this.parseUrl(process.env.RELDENS_PUBLIC_URL);
148
+ let hostUrlInfo = this.parseUrl(process.env.RELDENS_APP_HOST);
149
+ if(publicUrlInfo){
150
+ this.useHttps = publicUrlInfo.isHttps;
151
+ if(!this.developmentDomains.includes(publicUrlInfo.domain)){
152
+ this.developmentDomains.push(publicUrlInfo.domain);
153
+ }
141
154
  }
142
- if(publicDomain && !this.developmentDomains.includes(publicDomain)){
143
- this.developmentDomains.push(publicDomain);
155
+ if(hostUrlInfo){
156
+ if(!publicUrlInfo){
157
+ this.useHttps = hostUrlInfo.isHttps;
158
+ }
159
+ if(!this.developmentDomains.includes(hostUrlInfo.domain)){
160
+ this.developmentDomains.push(hostUrlInfo.domain);
161
+ }
144
162
  }
145
163
  }
146
164
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/server-utils",
3
3
  "scope": "@reldens",
4
- "version": "0.29.0",
4
+ "version": "0.30.0",
5
5
  "description": "Reldens - Server Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",