@reldens/cms 0.33.0 → 0.35.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.
package/lib/frontend.js CHANGED
@@ -38,6 +38,7 @@ class Frontend
38
38
  this.domainMapping = sc.get(props, 'domainMapping', {});
39
39
  this.siteKeyMapping = sc.get(props, 'siteKeyMapping', {});
40
40
  this.domainPublicUrlMapping = sc.get(props, 'domainPublicUrlMapping', {});
41
+ this.domainCdnMapping = sc.get(props, 'domainCdnMapping', {});
41
42
  this.defaultPublicUrl = sc.get(props, 'defaultPublicUrl', '');
42
43
  this.entitiesConfig = sc.get(props, 'entitiesConfig', {});
43
44
  this.templateEngine = false;
@@ -129,6 +130,7 @@ class Frontend
129
130
  projectRoot: this.projectRoot,
130
131
  publicPath: this.publicPath,
131
132
  domainPublicUrlMapping: this.domainPublicUrlMapping,
133
+ domainCdnMapping: this.domainCdnMapping,
132
134
  defaultPublicUrl: this.defaultPublicUrl,
133
135
  dynamicForm: this.dynamicForm,
134
136
  dynamicFormRenderer: this.dynamicFormRenderer
package/lib/manager.js CHANGED
@@ -63,7 +63,12 @@ class Manager
63
63
  this.domainPublicUrlMapping = sc.get(
64
64
  props,
65
65
  'domainPublicUrlMapping',
66
- sc.toJson(process.env.RELDENS_DOMAIN_PUBLIC_URL_MAPPING)
66
+ sc.toJson(process.env.RELDENS_DOMAIN_PUBLIC_URL_MAPPING, {})
67
+ );
68
+ this.domainCdnMapping = sc.get(
69
+ props,
70
+ 'domainCdnMapping',
71
+ sc.toJson(process.env.RELDENS_DOMAIN_CDN_MAPPING, {})
67
72
  );
68
73
  this.templateExtensions = sc.get(props, 'templateExtensions', ['.html', '.template']);
69
74
  this.cache = sc.get(props, 'cache', false);
@@ -249,6 +254,7 @@ class Manager
249
254
  };
250
255
  let appServerConfig = Object.assign({}, baseConfig, this.appServerConfig);
251
256
  if(this.domainMapping && 'object' === typeof this.domainMapping){
257
+ this.validateCdnMappingsInDevelopment();
252
258
  let mappingKeys = Object.keys(this.domainMapping);
253
259
  for(let domain of mappingKeys){
254
260
  this.appServerFactory.addDevelopmentDomain(domain);
@@ -263,6 +269,34 @@ class Manager
263
269
  return appServerConfig;
264
270
  }
265
271
 
272
+ validateCdnMappingsInDevelopment()
273
+ {
274
+ if(!sc.isObject(this.domainCdnMapping) || sc.isArray(this.domainCdnMapping)){
275
+ return;
276
+ }
277
+ if(0 === Object.keys(this.domainCdnMapping).length){
278
+ return;
279
+ }
280
+ if(!sc.isObject(this.developmentExternalDomains) || sc.isArray(this.developmentExternalDomains)){
281
+ Logger.warning('CDN mappings configured but developmentExternalDomains not provided. '
282
+ +'CDN assets may fail in development mode due to CORS. '
283
+ +'Add CDN domains to developmentExternalDomains configuration.');
284
+ return;
285
+ }
286
+ let cdnUrls = Object.keys(this.domainCdnMapping).map(domain => this.domainCdnMapping[domain]);
287
+ let missingCDNs = [];
288
+ for(let cdnUrl of cdnUrls){
289
+ let cdnHostname = cdnUrl.replace(/^https?:\/\//, '').split('/')[0];
290
+ if(!sc.hasOwn(this.developmentExternalDomains, cdnHostname)){
291
+ missingCDNs.push(cdnHostname);
292
+ }
293
+ }
294
+ if(0 < missingCDNs.length){
295
+ Logger.warning('CDN domains not found in developmentExternalDomains: '+missingCDNs.join(', ')
296
+ +'. Add them to avoid CORS issues in development mode.');
297
+ }
298
+ }
299
+
266
300
  async initializeCmsAfterInstall(props)
267
301
  {
268
302
  try {
@@ -533,6 +567,7 @@ class Manager
533
567
  domainMapping: this.domainMapping,
534
568
  siteKeyMapping: this.siteKeyMapping,
535
569
  domainPublicUrlMapping: this.domainPublicUrlMapping,
570
+ domainCdnMapping: this.domainCdnMapping,
536
571
  defaultPublicUrl: this.config.publicUrl,
537
572
  templateExtensions: this.templateExtensions,
538
573
  entitiesConfig: this.entitiesConfig,
@@ -33,9 +33,7 @@ class AssetTransformer
33
33
  if(!assetPath || assetPath.startsWith('http')){
34
34
  return assetPath;
35
35
  }
36
- return sc.get(currentRequest, 'publicUrl', '')
37
- +'/assets'
38
- +(assetPath.startsWith('/') ? assetPath : '/'+assetPath);
36
+ return sc.get(currentRequest, 'assetUrl', '')+'/assets'+(assetPath.startsWith('/') ? assetPath : '/'+assetPath);
39
37
  }
40
38
 
41
39
  }
@@ -16,6 +16,7 @@ class SystemVariablesProvider
16
16
  this.publicPath = sc.get(props, 'publicPath', './public');
17
17
  this.domainPublicUrlMapping = sc.get(props, 'domainPublicUrlMapping', {});
18
18
  this.defaultPublicUrl = sc.get(props, 'defaultPublicUrl', '');
19
+ this.domainCdnMapping = sc.get(props, 'domainCdnMapping', {});
19
20
  }
20
21
 
21
22
  buildSystemVariables(req, route, domain)
@@ -28,6 +29,7 @@ class SystemVariablesProvider
28
29
  currentRequest,
29
30
  currentRoute,
30
31
  currentDomain,
32
+ domainCdnMapping: this.domainCdnMapping,
31
33
  systemInfo
32
34
  };
33
35
  }
@@ -59,6 +61,7 @@ class SystemVariablesProvider
59
61
  if('' === baseUrl && '' !== this.defaultPublicUrl){
60
62
  baseUrl = this.defaultPublicUrl;
61
63
  }
64
+ let assetUrl = domain ? sc.get(this.domainCdnMapping, domain, publicUrl) : publicUrl;
62
65
  let fullUrl = protocol+'://'+host+originalUrl;
63
66
  return {
64
67
  method: sc.get(req, 'method', 'GET'),
@@ -75,6 +78,7 @@ class SystemVariablesProvider
75
78
  ip: sc.get(req, 'ip', ''),
76
79
  baseUrl,
77
80
  publicUrl,
81
+ assetUrl,
78
82
  defaultPublicUrl: this.defaultPublicUrl,
79
83
  timestamp: sc.getCurrentDate(),
80
84
  isSecure: 'https' === protocol
@@ -29,8 +29,9 @@ class TemplateEngine
29
29
  this.defaultDomain = sc.get(props, 'defaultDomain', 'default');
30
30
  this.projectRoot = sc.get(props, 'projectRoot', './');
31
31
  this.publicPath = sc.get(props, 'publicPath', './public');
32
- this.domainPublicUrlMapping = sc.get(props, 'domainPublicUrlMapping', {});
32
+ this.domainPublicUrlMapping = sc.isObject(props.domainPublicUrlMapping) && !sc.isArray(props.domainPublicUrlMapping) ? props.domainPublicUrlMapping : {};
33
33
  this.defaultPublicUrl = sc.get(props, 'defaultPublicUrl', '');
34
+ this.domainCdnMapping = sc.isObject(props.domainCdnMapping) && !sc.isArray(props.domainCdnMapping) ? props.domainCdnMapping : {};
34
35
  this.dynamicForm = sc.get(props, 'dynamicForm', false);
35
36
  this.dynamicFormRenderer = sc.get(props, 'dynamicFormRenderer', false);
36
37
  this.jsonFieldsParser = new JsonFieldsParser({entitiesConfig: sc.get(props, 'entitiesConfig', {})});
@@ -39,6 +40,7 @@ class TemplateEngine
39
40
  projectRoot: this.projectRoot,
40
41
  publicPath: this.publicPath,
41
42
  domainPublicUrlMapping: this.domainPublicUrlMapping,
43
+ domainCdnMapping: this.domainCdnMapping,
42
44
  defaultPublicUrl: this.defaultPublicUrl
43
45
  });
44
46
  this.entitiesTransformer = new EntitiesTransformer({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/cms",
3
3
  "scope": "@reldens",
4
- "version": "0.33.0",
4
+ "version": "0.35.0",
5
5
  "description": "Reldens - CMS",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -33,10 +33,10 @@
33
33
  "url": "https://github.com/damian-pastorini/reldens-cms/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@reldens/server-utils": "^0.33.0",
36
+ "@reldens/server-utils": "^0.36.0",
37
37
  "@reldens/storage": "^0.73.0",
38
38
  "@reldens/utils": "^0.53.0",
39
- "dotenv": "17.2.2",
39
+ "dotenv": "17.2.3",
40
40
  "mustache": "4.2.0"
41
41
  }
42
42
  }