5htp-core 0.6.1-3 → 0.6.1-5
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.
|
@@ -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 =>
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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)
|
package/common/router/index.ts
CHANGED
|
@@ -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-
|
|
4
|
+
"version": "0.6.1-5",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -222,24 +222,23 @@ export default class ServerRouter
|
|
|
222
222
|
----------------------------------*/
|
|
223
223
|
|
|
224
224
|
public async renderStatic(
|
|
225
|
-
|
|
225
|
+
url: string,
|
|
226
226
|
options: TRouteOptions["static"],
|
|
227
227
|
rendered?: any
|
|
228
228
|
) {
|
|
229
229
|
|
|
230
230
|
// Wildcard: tell that the newly rendered pages should be cached
|
|
231
|
-
if (
|
|
231
|
+
if (url === '*' || !url)
|
|
232
232
|
return;
|
|
233
233
|
|
|
234
234
|
if (!rendered) {
|
|
235
235
|
|
|
236
|
-
const fullUrl = this.url(
|
|
237
|
-
console.log('[router] renderStatic', fullUrl);
|
|
238
|
-
|
|
236
|
+
const fullUrl = this.url(url, {}, true);
|
|
239
237
|
const response = await got( fullUrl, {
|
|
240
238
|
method: 'GET',
|
|
241
239
|
headers: {
|
|
242
|
-
'Accept': 'text/html'
|
|
240
|
+
'Accept': 'text/html',
|
|
241
|
+
'bypasscache': '1'
|
|
243
242
|
},
|
|
244
243
|
throwHttpErrors: false,
|
|
245
244
|
});
|
|
@@ -252,7 +251,7 @@ export default class ServerRouter
|
|
|
252
251
|
rendered = response.body;
|
|
253
252
|
}
|
|
254
253
|
|
|
255
|
-
this.cache[
|
|
254
|
+
this.cache[url] = {
|
|
256
255
|
rendered: rendered,
|
|
257
256
|
options: options,
|
|
258
257
|
expire: typeof options === 'object'
|
|
@@ -499,15 +498,12 @@ export default class ServerRouter
|
|
|
499
498
|
"no-store, no-cache, must-revalidate, proxy-revalidate"
|
|
500
499
|
);
|
|
501
500
|
|
|
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
501
|
// Create request
|
|
510
502
|
let requestId = uuid();
|
|
503
|
+
const cachedPage = req.headers['bypasscache']
|
|
504
|
+
? undefined
|
|
505
|
+
: this.cache[req.path];
|
|
506
|
+
|
|
511
507
|
const request = new ServerRequest(
|
|
512
508
|
requestId,
|
|
513
509
|
|
|
@@ -533,13 +529,25 @@ export default class ServerRouter
|
|
|
533
529
|
return await this.resolveApiBatch(request.data.fetchers, request);
|
|
534
530
|
|
|
535
531
|
} else {
|
|
536
|
-
response = await this.resolve(
|
|
532
|
+
response = await this.resolve(
|
|
533
|
+
request,
|
|
534
|
+
// If cached page, we only run routes with priority >= 10
|
|
535
|
+
cachedPage ? true : false
|
|
536
|
+
);
|
|
537
537
|
}
|
|
538
538
|
} catch (e) {
|
|
539
539
|
response = await this.handleError(e, request);
|
|
540
540
|
}
|
|
541
541
|
|
|
542
542
|
if (!res.headersSent) {
|
|
543
|
+
|
|
544
|
+
// Static pages
|
|
545
|
+
if (cachedPage) {
|
|
546
|
+
console.log('[router] Get static page from cache', req.path);
|
|
547
|
+
res.send( cachedPage.rendered );
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
|
|
543
551
|
// Status
|
|
544
552
|
res.status(response.statusCode);
|
|
545
553
|
// Headers
|
|
@@ -572,7 +580,10 @@ export default class ServerRouter
|
|
|
572
580
|
return contextServices;
|
|
573
581
|
}
|
|
574
582
|
|
|
575
|
-
public resolve = (
|
|
583
|
+
public resolve = (
|
|
584
|
+
request: ServerRequest<this>,
|
|
585
|
+
isStatic?: boolean
|
|
586
|
+
) => new Promise<ServerResponse<this>>((resolve, reject) => {
|
|
576
587
|
|
|
577
588
|
// Create request context so we can access request context across all the request-triggered libs
|
|
578
589
|
context.run({
|
|
@@ -613,6 +624,9 @@ export default class ServerRouter
|
|
|
613
624
|
// Classic routes
|
|
614
625
|
for (route of this.routes) {
|
|
615
626
|
|
|
627
|
+
if (isStatic && !route.options.whenStatic)
|
|
628
|
+
continue;
|
|
629
|
+
|
|
616
630
|
// Match Method
|
|
617
631
|
if (request.method !== route.method && route.method !== '*')
|
|
618
632
|
continue;
|
package/types/icons.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TIcones = "solid/spinner-third"|"long-arrow-right"|"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"|"
|
|
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"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"angle-down"|"info-circle"|"check-circle"|"exclamation-circle"|"bars"|"font"|"tag"|"compress"|"bolt"|"puzzle-piece"|"planet-ringed"|"chart-bar"|"power-off"|"heart"|"lock"|"eye"|"credit-card"|"at"|"brands/linkedin"|"key"|"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"|"angle-left"|"angle-right"|"check"|"paper-plane"|"long-arrow-left"|"trash"|"meh-rolling-eyes"|"arrow-left"|"arrow-right"|"unlink"|"pen"|"link"|"file"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"empty-set"|"horizontal-rule"|"page-break"|"image"|"table"|"poll"|"columns"|"sticky-note"|"caret-right"|"plus"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"
|