5htp-core 0.6.1-2 → 0.6.1-4

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.
@@ -151,8 +151,8 @@ export default ({ service: clientRouter, loaderComponent }: TProps) => {
151
151
  // But when we call setLayout, the style of the previous layout are still oaded and applied
152
152
  // Find a way to unload the previous layout / page resources before to load the new one
153
153
  console.log(LogPrefix, `Changing layout. Before:`, curLayout, 'New layout:', newLayout);
154
- window.location.replace( request ? request.url : window.location.href );
155
- return page; // Don't spread since it's an instance
154
+ /*window.location.replace( request ? request.url : window.location.href );
155
+ return page; // Don't spread since it's an instance*/
156
156
 
157
157
  context.app.setLayout(newLayout);
158
158
  }
@@ -118,16 +118,36 @@ export default class ApiClient implements ApiClientService {
118
118
  // For async calls: api.post(...).then((data) => ...)
119
119
  then: (callback: (data: any) => void) => this.fetchAsync<TData>(...args)
120
120
  .then(callback)
121
- .catch( e => this.app.handleError(e)),
121
+ .catch( e => {
122
+ this.app.handleError(e);
123
+
124
+ // Don't run what is next
125
+ return {
126
+ then: () => {},
127
+ catch: () => {},
128
+ finally: (callback: () => void) => {
129
+ callback();
130
+ },
131
+ }
132
+ }),
122
133
 
123
134
  // Default error behavior only if not handled before by the app
124
- catch: (callback: (data: any) => void) => this.fetchAsync<TData>(...args)
135
+ catch: (callback: (data: any) => false | void) => this.fetchAsync<TData>(...args)
125
136
  .catch((e) => {
126
- try {
127
- callback(e);
128
- } catch (error) {
129
- this.app.handleError(e)
137
+
138
+ const shouldThrow = callback(e);
139
+ if (shouldThrow)
140
+ this.app.handleError(e);
141
+
142
+ // Don't run what is next
143
+ return {
144
+ then: () => {},
145
+ catch: () => {},
146
+ finally: (callback: () => void) => {
147
+ callback();
148
+ },
130
149
  }
150
+
131
151
  }),
132
152
 
133
153
  finally: (callback: () => void) => this.fetchAsync<TData>(...args)
@@ -102,6 +102,7 @@ export type TRouteOptions = {
102
102
  refresh?: string,
103
103
  urls: string[]
104
104
  },
105
+ whenStatic?: boolean, // If true, the route is only executed even if the page is cached
105
106
  canonicalParams?: string[], // For SEO + unique ID for static cache
106
107
  layout?: false | string, // The nale of the layout
107
108
 
@@ -18,6 +18,8 @@ export type TFetcher<TData extends any = unknown> = {
18
18
 
19
19
  // For async calls: api.post(...).then((data) => ...)
20
20
  then: (callback: (data: TData) => void) => Promise<TData>,
21
+ catch: (callback: (data: any) => false | void) => Promise<TData>,
22
+ finally: (callback: () => void) => Promise<TData>,
21
23
  run: () => Promise<TData>,
22
24
 
23
25
  method: HttpMethod,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.6.1-2",
4
+ "version": "0.6.1-4",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -67,8 +67,8 @@
67
67
  "object-sizeof": "^1.6.3",
68
68
  "path-to-regexp": "^6.2.0",
69
69
  "picomatch": "^2.3.1",
70
- "preact": "^10.22.1",
71
- "preact-render-to-string": "^6.5.5",
70
+ "preact": "^10.27.1",
71
+ "preact-render-to-string": "^6.6.1",
72
72
  "prettier": "^3.3.3",
73
73
  "react-scrollbars-custom": "^4.0.27",
74
74
  "react-slider": "^2.0.1",
@@ -233,7 +233,7 @@ export default class ServerRouter
233
233
 
234
234
  if (!rendered) {
235
235
 
236
- const fullUrl = this.url(path, {}, true);
236
+ const fullUrl = this.url(path + '#bypassCache', {}, true);
237
237
  console.log('[router] renderStatic', fullUrl);
238
238
 
239
239
  const response = await got( fullUrl, {
@@ -266,11 +266,11 @@ export default class ServerRouter
266
266
 
267
267
  console.log('[router] refreshStaticPages');
268
268
 
269
- for (const pageId in this.cache) {
270
- const page = this.cache[pageId];
271
- if (page.path && page.expire && page.expire < Date.now()) {
269
+ for (const pageUrl in this.cache) {
270
+ const page = this.cache[pageUrl];
271
+ if (page.expire && page.expire < Date.now()) {
272
272
 
273
- this.renderStatic(page.path, page.options);
273
+ this.renderStatic(pageUrl, page.options);
274
274
 
275
275
  }
276
276
  }
@@ -499,15 +499,12 @@ export default class ServerRouter
499
499
  "no-store, no-cache, must-revalidate, proxy-revalidate"
500
500
  );
501
501
 
502
- // Static pages
503
- if (this.cache[req.path]) {
504
- console.log('[router] Get static page from cache', req.path);
505
- res.send( this.cache[req.path].rendered );
506
- return;
507
- }
508
-
509
502
  // Create request
510
503
  let requestId = uuid();
504
+ const cachedPage = req.url.endsWith('#bypassCache')
505
+ ? undefined
506
+ : this.cache[req.path];
507
+
511
508
  const request = new ServerRequest(
512
509
  requestId,
513
510
 
@@ -533,13 +530,25 @@ export default class ServerRouter
533
530
  return await this.resolveApiBatch(request.data.fetchers, request);
534
531
 
535
532
  } else {
536
- response = await this.resolve(request);
533
+ response = await this.resolve(
534
+ request,
535
+ // If cached page, we only run routes with priority >= 10
536
+ cachedPage ? true : false
537
+ );
537
538
  }
538
539
  } catch (e) {
539
540
  response = await this.handleError(e, request);
540
541
  }
541
542
 
542
543
  if (!res.headersSent) {
544
+
545
+ // Static pages
546
+ if (cachedPage) {
547
+ console.log('[router] Get static page from cache', req.path);
548
+ res.send( cachedPage.rendered );
549
+ return;
550
+ }
551
+
543
552
  // Status
544
553
  res.status(response.statusCode);
545
554
  // Headers
@@ -572,7 +581,10 @@ export default class ServerRouter
572
581
  return contextServices;
573
582
  }
574
583
 
575
- public resolve = (request: ServerRequest<this>) => new Promise<ServerResponse<this>>((resolve, reject) => {
584
+ public resolve = (
585
+ request: ServerRequest<this>,
586
+ isStatic?: boolean
587
+ ) => new Promise<ServerResponse<this>>((resolve, reject) => {
576
588
 
577
589
  // Create request context so we can access request context across all the request-triggered libs
578
590
  context.run({
@@ -613,6 +625,9 @@ export default class ServerRouter
613
625
  // Classic routes
614
626
  for (route of this.routes) {
615
627
 
628
+ if (isStatic && !route.options.whenStatic)
629
+ continue;
630
+
616
631
  // Match Method
617
632
  if (request.method !== route.method && route.method !== '*')
618
633
  continue;
package/types/icons.d.ts CHANGED
@@ -1 +1 @@
1
- export type TIcones = "solid/spinner-third"|"long-arrow-right"|"times-circle"|"brands/whatsapp"|"times"|"search"|"user"|"rocket"|"globe"|"bullhorn"|"briefcase"|"chart-line"|"handshake"|"ellipsis-h"|"brands/google"|"brands/reddit-alien"|"brands/linkedin-in"|"brands/github"|"robot"|"comments"|"user-friends"|"angle-down"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"info-circle"|"check-circle"|"exclamation-circle"|"comment-alt"|"chart-bar"|"power-off"|"home"|"user-circle"|"newspaper"|"plus-circle"|"brands/linkedin"|"brands/twitter"|"brands/facebook"|"heart"|"lock"|"eye"|"credit-card"|"at"|"key"|"bars"|"font"|"tag"|"compress"|"bolt"|"puzzle-piece"|"planet-ringed"|"database"|"solid/fire"|"usd-circle"|"lightbulb"|"solid/dollar-sign"|"download"|"code"|"solid/clock"|"exclamation"|"solid/download"|"seedling"|"palette"|"car"|"plane"|"university"|"hard-hat"|"graduation-cap"|"cogs"|"film"|"leaf"|"tshirt"|"utensils"|"map-marked-alt"|"dumbbell"|"stethoscope"|"concierge-bell"|"book"|"shield-alt"|"gavel"|"industry"|"square-root-alt"|"pills"|"medal"|"capsules"|"balance-scale"|"praying-hands"|"shopping-cart"|"flask"|"futbol"|"microchip"|"satellite-dish"|"shipping-fast"|"passport"|"tools"|"angle-left"|"angle-right"|"check"|"paper-plane"|"trash"|"arrow-left"|"arrow-right"|"meh-rolling-eyes"|"unlink"|"pen"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"link"|"file"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"plus"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"
1
+ export type TIcones = "solid/spinner-third"|"long-arrow-right"|"times-circle"|"brands/whatsapp"|"times"|"search"|"user"|"rocket"|"globe"|"bullhorn"|"briefcase"|"chart-line"|"handshake"|"ellipsis-h"|"brands/google"|"brands/reddit-alien"|"brands/linkedin-in"|"brands/github"|"robot"|"comments"|"user-friends"|"angle-down"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"info-circle"|"check-circle"|"exclamation-circle"|"heart"|"lock"|"eye"|"credit-card"|"at"|"brands/linkedin"|"key"|"chart-bar"|"power-off"|"bars"|"font"|"tag"|"compress"|"bolt"|"puzzle-piece"|"planet-ringed"|"exclamation"|"solid/download"|"seedling"|"palette"|"car"|"plane"|"university"|"hard-hat"|"graduation-cap"|"cogs"|"film"|"leaf"|"tshirt"|"utensils"|"map-marked-alt"|"dumbbell"|"stethoscope"|"concierge-bell"|"book"|"shield-alt"|"gavel"|"industry"|"square-root-alt"|"newspaper"|"pills"|"medal"|"capsules"|"balance-scale"|"home"|"praying-hands"|"shopping-cart"|"flask"|"futbol"|"microchip"|"satellite-dish"|"shipping-fast"|"passport"|"tools"|"database"|"solid/fire"|"usd-circle"|"lightbulb"|"solid/dollar-sign"|"download"|"code"|"solid/clock"|"user-circle"|"plus-circle"|"brands/twitter"|"brands/facebook"|"comment-alt"|"paper-plane"|"check"|"long-arrow-left"|"angle-left"|"angle-right"|"trash"|"meh-rolling-eyes"|"arrow-left"|"arrow-right"|"bold"|"italic"|"underline"|"link"|"strikethrough"|"subscript"|"superscript"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"unlink"|"pen"|"file"|"plus"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"