cloudcommerce 0.0.72 → 0.0.73
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/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/lib/firebase/serve-storefront.js +13 -32
- package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/ssr/src/firebase/serve-storefront.ts +13 -37
- package/packages/storefront/dist/client/assets/{404-500-_...d4aa8aff.css → _...d4aa8aff.css} +0 -0
- package/packages/storefront/dist/client/assets/{404-500-index.d9230d24.css → fallback-index.d9230d24.css} +0 -0
- package/packages/storefront/dist/client/assets/{404.b3ead908.css → fallback.9745a8aa.css} +1 -1
- package/packages/storefront/dist/server/entry.mjs +146 -174
- package/packages/storefront/package.json +1 -1
- package/packages/storefront/src/lib/ssr-context.ts +54 -30
- package/packages/storefront/src/lib/views/{404.astro → fallback.astro} +1 -1
- package/packages/storefront/src/pages/[...slug].astro +7 -2
- package/packages/storefront/src/pages/{404.astro → fallback.astro} +2 -2
- package/packages/storefront/src/pages/index.astro +7 -2
- package/packages/types/package.json +1 -1
- package/packages/storefront/dist/client/assets/500.d5d7700b.css +0 -1
- package/packages/storefront/src/lib/views/500.astro +0 -79
- package/packages/storefront/src/pages/500.astro +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.73](https://github.com/ecomplus/cloud-commerce/compare/v0.0.72...v0.0.73) (2022-09-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **ssr:** Fix fallback and errors and skip cache/redirect handled by Astro SSR ([abe19ae](https://github.com/ecomplus/cloud-commerce/commit/abe19ae585698c7621aa3bc6cf26bbf8f816824a))
|
|
11
|
+
* **storefront:** Must prefetch defined API endpoints also for non-slug pages (home) ([c55f201](https://github.com/ecomplus/cloud-commerce/commit/c55f201c76b96c19c334c460df35baa5715ac5b1))
|
|
12
|
+
* **storefront:** Send `X-SSR-Error` with error message only ([7fafde1](https://github.com/ecomplus/cloud-commerce/commit/7fafde110ee9b6d9139b2ad0f7959826c1b08e74))
|
|
13
|
+
|
|
5
14
|
### [0.0.72](https://github.com/ecomplus/cloud-commerce/compare/v0.0.71...v0.0.72) (2022-09-09)
|
|
6
15
|
|
|
7
16
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcommerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.73",
|
|
5
5
|
"description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
|
|
6
6
|
"main": "packages/api/lib/index.js",
|
|
7
7
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { join as joinPath } from 'path';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
3
|
|
|
4
|
-
const { STOREFRONT_BASE_DIR
|
|
4
|
+
const { STOREFRONT_BASE_DIR } = process.env;
|
|
5
5
|
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
6
6
|
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
7
|
-
const isLongCache = String(STOREFRONT_LONG_CACHE).toLowerCase() === 'true';
|
|
8
7
|
|
|
9
8
|
export default (req, res) => {
|
|
10
9
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
@@ -14,32 +13,16 @@ export default (req, res) => {
|
|
|
14
13
|
.set('Cache-Control', (typeof global.cache_control === 'function' && global.cache_control(status))
|
|
15
14
|
|| defaultCache);
|
|
16
15
|
};
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
sMaxAge *= 10;
|
|
21
|
-
}
|
|
22
|
-
let cacheControl = `public, max-age=30, s-maxage=${sMaxAge}`;
|
|
23
|
-
if (status === 302) {
|
|
24
|
-
cacheControl += ', proxy-revalidate';
|
|
25
|
-
}
|
|
26
|
-
setStatusAndCache(status, cacheControl)
|
|
27
|
-
.set('Location', toUrl).end();
|
|
28
|
-
};
|
|
29
|
-
const fallback = (status = 404) => {
|
|
30
|
-
const is404 = status === 404;
|
|
31
|
-
if (is404 && url.slice(-1) === '/') {
|
|
32
|
-
redirect(url.slice(0, -1));
|
|
33
|
-
} else if (url !== `/${status}` && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
34
|
-
setStatusAndCache(status, `public, max-age=${(isLongCache ? 120 : 30)}`)
|
|
16
|
+
const fallback = (err, status = 500) => {
|
|
17
|
+
if (url !== '/fallback' && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
18
|
+
setStatusAndCache(status, 'public, max-age=120')
|
|
35
19
|
.send('<html><head>'
|
|
36
|
-
+
|
|
37
|
-
+
|
|
20
|
+
+ '<meta http-equiv="refresh" content="0; '
|
|
21
|
+
+ `url=/fallback?status=${status}&url=${encodeURIComponent(url)}"/>`
|
|
22
|
+
+ `</head><body>${err.toString()}</body></html>`);
|
|
38
23
|
} else {
|
|
39
|
-
setStatusAndCache(status,
|
|
40
|
-
|
|
41
|
-
: 'public, max-age=60, s-maxage=300')
|
|
42
|
-
.end();
|
|
24
|
+
setStatusAndCache(status, 'public, max-age=120, s-maxage=600')
|
|
25
|
+
.send(err.toString());
|
|
43
26
|
}
|
|
44
27
|
};
|
|
45
28
|
/*
|
|
@@ -49,19 +32,17 @@ export default (req, res) => {
|
|
|
49
32
|
*/
|
|
50
33
|
global.ssr_handler(req, res, async (err) => {
|
|
51
34
|
if (err) {
|
|
52
|
-
res.set('X-SSR-Error', err.
|
|
53
|
-
fallback(
|
|
35
|
+
res.set('X-SSR-Error', err.message);
|
|
36
|
+
fallback(err);
|
|
54
37
|
return;
|
|
55
38
|
}
|
|
56
39
|
const local = new URL(`.${url}`, clientRoot);
|
|
57
40
|
try {
|
|
58
41
|
const data = await readFile(local);
|
|
59
|
-
setStatusAndCache(200,
|
|
60
|
-
? 'public, max-age=60, s-maxage=604800'
|
|
61
|
-
: 'public, max-age=60, s-maxage=600, stale-while-revalidate=2592000')
|
|
42
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
62
43
|
.send(data);
|
|
63
44
|
} catch {
|
|
64
|
-
fallback();
|
|
45
|
+
fallback(err, 404);
|
|
65
46
|
}
|
|
66
47
|
});
|
|
67
48
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-storefront.js","sourceRoot":"","sources":["../../src/firebase/serve-storefront.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,
|
|
1
|
+
{"version":3,"file":"serve-storefront.js","sourceRoot":"","sources":["../../src/firebase/serve-storefront.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAC5C,MAAM,OAAO,GAAG,mBAAmB,IAAI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,CAAC,CAAC;IAEF;;;;MAIE;IACF,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAQ,EAAE,EAAE;QAC9C,IAAI,GAAG,EAAE;YACP,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,OAAO;SACR;QACD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;QAC7C,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnC,iBAAiB,CAAC,GAAG,EAAE,kCAAkC,CAAC;iBACvD,IAAI,CAAC,IAAI,CAAC,CAAC;SACf;QAAC,MAAM;YACN,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACpB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -2,14 +2,9 @@ import type { Request, Response } from 'firebase-functions';
|
|
|
2
2
|
import { join as joinPath } from 'path';
|
|
3
3
|
import { readFile } from 'fs/promises';
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
STOREFRONT_BASE_DIR,
|
|
7
|
-
STOREFRONT_LONG_CACHE,
|
|
8
|
-
} = process.env;
|
|
9
|
-
|
|
5
|
+
const { STOREFRONT_BASE_DIR } = process.env;
|
|
10
6
|
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
11
7
|
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
12
|
-
const isLongCache = String(STOREFRONT_LONG_CACHE).toLowerCase() === 'true';
|
|
13
8
|
|
|
14
9
|
export default (req: Request, res: Response) => {
|
|
15
10
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
@@ -24,33 +19,16 @@ export default (req: Request, res: Response) => {
|
|
|
24
19
|
);
|
|
25
20
|
};
|
|
26
21
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
sMaxAge *= 10;
|
|
31
|
-
}
|
|
32
|
-
let cacheControl = `public, max-age=30, s-maxage=${sMaxAge}`;
|
|
33
|
-
if (status === 302) {
|
|
34
|
-
cacheControl += ', proxy-revalidate';
|
|
35
|
-
}
|
|
36
|
-
setStatusAndCache(status, cacheControl)
|
|
37
|
-
.set('Location', toUrl).end();
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const fallback = (status = 404) => {
|
|
41
|
-
const is404 = status === 404;
|
|
42
|
-
if (is404 && url.slice(-1) === '/') {
|
|
43
|
-
redirect(url.slice(0, -1));
|
|
44
|
-
} else if (url !== `/${status}` && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
45
|
-
setStatusAndCache(status, `public, max-age=${(isLongCache ? 120 : 30)}`)
|
|
22
|
+
const fallback = (err: any, status = 500) => {
|
|
23
|
+
if (url !== '/fallback' && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
24
|
+
setStatusAndCache(status, 'public, max-age=120')
|
|
46
25
|
.send('<html><head>'
|
|
47
|
-
+
|
|
48
|
-
|
|
26
|
+
+ '<meta http-equiv="refresh" content="0; '
|
|
27
|
+
+ `url=/fallback?status=${status}&url=${encodeURIComponent(url)}"/>`
|
|
28
|
+
+ `</head><body>${err.toString()}</body></html>`);
|
|
49
29
|
} else {
|
|
50
|
-
setStatusAndCache(status,
|
|
51
|
-
|
|
52
|
-
: 'public, max-age=60, s-maxage=300')
|
|
53
|
-
.end();
|
|
30
|
+
setStatusAndCache(status, 'public, max-age=120, s-maxage=600')
|
|
31
|
+
.send(err.toString());
|
|
54
32
|
}
|
|
55
33
|
};
|
|
56
34
|
|
|
@@ -61,19 +39,17 @@ export default (req: Request, res: Response) => {
|
|
|
61
39
|
*/
|
|
62
40
|
global.ssr_handler(req, res, async (err: any) => {
|
|
63
41
|
if (err) {
|
|
64
|
-
res.set('X-SSR-Error', err.
|
|
65
|
-
fallback(
|
|
42
|
+
res.set('X-SSR-Error', err.message);
|
|
43
|
+
fallback(err);
|
|
66
44
|
return;
|
|
67
45
|
}
|
|
68
46
|
const local = new URL(`.${url}`, clientRoot);
|
|
69
47
|
try {
|
|
70
48
|
const data = await readFile(local);
|
|
71
|
-
setStatusAndCache(200,
|
|
72
|
-
? 'public, max-age=60, s-maxage=604800'
|
|
73
|
-
: 'public, max-age=60, s-maxage=600, stale-while-revalidate=2592000')
|
|
49
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
74
50
|
.send(data);
|
|
75
51
|
} catch {
|
|
76
|
-
fallback();
|
|
52
|
+
fallback(err, 404);
|
|
77
53
|
}
|
|
78
54
|
});
|
|
79
55
|
};
|
package/packages/storefront/dist/client/assets/{404-500-_...d4aa8aff.css → _...d4aa8aff.css}
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--astro-gradient: linear-gradient(0deg,#4F39FA, #DA62C4)}h1:where(.astro-
|
|
1
|
+
:root{--astro-gradient: linear-gradient(0deg,#4F39FA, #DA62C4)}h1:where(.astro-HIITKN5F){margin:2rem 0}main:where(.astro-HIITKN5F){margin:auto;padding:1em;max-width:60ch}.text-gradient:where(.astro-HIITKN5F){font-weight:900;background-image:var(--astro-gradient);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-size:100% 200%;background-position-y:100%;border-radius:.4rem;animation:pulse 4s ease-in-out infinite}@keyframes pulse{0%,to{background-position-y:0%}50%{background-position-y:80%}}.instructions:where(.astro-HIITKN5F){line-height:1.6;margin:1rem 0;background:#4F39FA;padding:1rem;border-radius:.4rem;color:var(--color-bg)}.instructions:where(.astro-HIITKN5F) code:where(.astro-HIITKN5F){font-size:.875em;border:.1em solid var(--color-border);border-radius:4px;padding:.15em .25em}.link-card-grid:where(.astro-HIITKN5F){display:grid;grid-template-columns:repeat(auto-fit,minmax(24ch,1fr));gap:1rem;padding:0}
|