cloudcommerce 0.0.79 → 0.0.81
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 +24 -41
- package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -1
- package/packages/ssr/package.json +2 -1
- package/packages/ssr/src/firebase/serve-storefront.ts +29 -60
- package/packages/storefront/package.json +1 -1
- package/packages/types/package.json +1 -1
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.81](https://github.com/ecomplus/cloud-commerce/compare/v0.0.80...v0.0.81) (2022-09-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **ssr:** Use `compression` pkg (middleware) to gzip ([714c8b3](https://github.com/ecomplus/cloud-commerce/commit/714c8b3f502082a6a395b40e7a792540cd9af861))
|
|
11
|
+
|
|
12
|
+
### [0.0.80](https://github.com/ecomplus/cloud-commerce/compare/v0.0.79...v0.0.80) (2022-09-16)
|
|
13
|
+
|
|
5
14
|
### [0.0.79](https://github.com/ecomplus/cloud-commerce/compare/v0.0.78...v0.0.79) (2022-09-16)
|
|
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.81",
|
|
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,16 +1,18 @@
|
|
|
1
|
-
import { join as joinPath } from '
|
|
2
|
-
import { readFile } from '
|
|
3
|
-
import
|
|
4
|
-
import logger from 'firebase-functions/lib/logger';
|
|
1
|
+
import { join as joinPath } from 'path';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import compression from 'compression';
|
|
5
4
|
|
|
6
5
|
const { STOREFRONT_BASE_DIR } = process.env;
|
|
7
6
|
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
8
7
|
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
8
|
+
const compress = compression();
|
|
9
9
|
|
|
10
10
|
export default (req, res) => {
|
|
11
11
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
12
12
|
const setStatusAndCache = (status, defaultCache) => {
|
|
13
|
-
return res.status(status)
|
|
13
|
+
return res.status(status)
|
|
14
|
+
.set('X-SSR-ID', `v1/${Date.now()}`)
|
|
15
|
+
.set('Cache-Control', (typeof global.cache_control === 'function' && global.cache_control(status))
|
|
14
16
|
|| defaultCache);
|
|
15
17
|
};
|
|
16
18
|
const fallback = (err, status = 500) => {
|
|
@@ -25,46 +27,27 @@ export default (req, res) => {
|
|
|
25
27
|
.send(err.toString());
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
|
-
res
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return res.WRITEHEAD(statusCode, headers);
|
|
36
|
-
};
|
|
37
|
-
res.WRITE = res.write;
|
|
38
|
-
res.write = (chunk) => {
|
|
39
|
-
gzip(chunk, (err, data) => {
|
|
30
|
+
compress(req, res, async () => {
|
|
31
|
+
/*
|
|
32
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
33
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
34
|
+
global.ssr_handler = ssrHandler;
|
|
35
|
+
*/
|
|
36
|
+
global.ssr_handler(req, res, async (err) => {
|
|
40
37
|
if (err) {
|
|
41
|
-
|
|
38
|
+
res.set('X-SSR-Error', err.message);
|
|
42
39
|
fallback(err);
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
43
|
+
try {
|
|
44
|
+
const data = await readFile(local);
|
|
45
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
46
|
+
.send(data);
|
|
47
|
+
} catch {
|
|
48
|
+
fallback(err, 404);
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
|
-
return true;
|
|
48
|
-
};
|
|
49
|
-
/*
|
|
50
|
-
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
51
|
-
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
52
|
-
global.ssr_handler = ssrHandler;
|
|
53
|
-
*/
|
|
54
|
-
global.ssr_handler(req, res, async (err) => {
|
|
55
|
-
if (err) {
|
|
56
|
-
res.set('X-SSR-Error', err.message);
|
|
57
|
-
fallback(err);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const local = new URL(`.${url}`, clientRoot);
|
|
61
|
-
try {
|
|
62
|
-
const data = await readFile(local);
|
|
63
|
-
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
64
|
-
.send(data);
|
|
65
|
-
} catch {
|
|
66
|
-
fallback(err, 404);
|
|
67
|
-
}
|
|
68
51
|
});
|
|
69
52
|
};
|
|
70
53
|
// # sourceMappingURL=serve-storefront.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-storefront.js","sourceRoot":"","sources":["../../src/firebase/serve-storefront.ts"],"names":[],"mappings":"
|
|
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;AACvC,OAAO,WAAW,MAAM,aAAa,CAAC;AAEtC,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAC5C,MAAM,OAAO,GAAG,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AACrD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/E,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;AAE/B,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEhE,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,YAAoB,EAAE,EAAE;QACjE,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;aACtB,GAAG,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;aACnC,GAAG,CACF,eAAe,EACf,CAAC,OAAO,MAAM,CAAC,aAAa,KAAK,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;eACvE,YAAY,CAClB,CAAC;IACN,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,CAAC,GAA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7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.81",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront SSR",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@cloudcommerce/api": "workspace:*",
|
|
27
27
|
"@cloudcommerce/firebase": "workspace:*",
|
|
28
|
+
"compression": "^1.7.4",
|
|
28
29
|
"firebase-admin": "^11.0.1",
|
|
29
30
|
"firebase-functions": "^3.23.0",
|
|
30
31
|
"source-map-support": "^0.5.21"
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import type { Request, Response } from 'firebase-functions';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { gzip } from 'node:zlib';
|
|
6
|
-
import logger from 'firebase-functions/lib/logger';
|
|
2
|
+
import { join as joinPath } from 'path';
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
import compression from 'compression';
|
|
7
5
|
|
|
8
6
|
const { STOREFRONT_BASE_DIR } = process.env;
|
|
9
7
|
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
10
8
|
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
9
|
+
const compress = compression();
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
WRITEHEAD?: Response['writeHead'],
|
|
14
|
-
WRITE?: Response['write'],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default (req: Request, res: InterceptedResponse) => {
|
|
11
|
+
export default (req: Request, res: Response) => {
|
|
18
12
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
19
13
|
|
|
20
14
|
const setStatusAndCache = (status: number, defaultCache: string) => {
|
|
21
|
-
return res.status(status)
|
|
22
|
-
'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
return res.status(status)
|
|
16
|
+
.set('X-SSR-ID', `v1/${Date.now()}`)
|
|
17
|
+
.set(
|
|
18
|
+
'Cache-Control',
|
|
19
|
+
(typeof global.cache_control === 'function' && global.cache_control(status))
|
|
20
|
+
|| defaultCache,
|
|
21
|
+
);
|
|
26
22
|
};
|
|
27
23
|
|
|
28
24
|
const fallback = (err: any, status = 500) => {
|
|
@@ -38,53 +34,26 @@ export default (req: Request, res: InterceptedResponse) => {
|
|
|
38
34
|
}
|
|
39
35
|
};
|
|
40
36
|
|
|
41
|
-
res
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
headers['Transfer-Encoding'] = 'gzip, chunked';
|
|
49
|
-
headers['X-SSR-ID'] = `v1/${Date.now()}`;
|
|
50
|
-
}
|
|
51
|
-
return (res.WRITEHEAD as Response['writeHead'])(
|
|
52
|
-
statusCode,
|
|
53
|
-
headers as OutgoingHttpHeaders,
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
res.WRITE = res.write;
|
|
58
|
-
res.write = (chunk: any) => {
|
|
59
|
-
gzip(chunk, (err, data) => {
|
|
37
|
+
compress(req, res, async () => {
|
|
38
|
+
/*
|
|
39
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
40
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
41
|
+
global.ssr_handler = ssrHandler;
|
|
42
|
+
*/
|
|
43
|
+
global.ssr_handler(req, res, async (err: any) => {
|
|
60
44
|
if (err) {
|
|
61
|
-
|
|
45
|
+
res.set('X-SSR-Error', err.message);
|
|
62
46
|
fallback(err);
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
50
|
+
try {
|
|
51
|
+
const data = await readFile(local);
|
|
52
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
53
|
+
.send(data);
|
|
54
|
+
} catch {
|
|
55
|
+
fallback(err, 404);
|
|
65
56
|
}
|
|
66
57
|
});
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/*
|
|
71
|
-
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
72
|
-
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
73
|
-
global.ssr_handler = ssrHandler;
|
|
74
|
-
*/
|
|
75
|
-
global.ssr_handler(req, res, async (err: any) => {
|
|
76
|
-
if (err) {
|
|
77
|
-
res.set('X-SSR-Error', err.message);
|
|
78
|
-
fallback(err);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const local = new URL(`.${url}`, clientRoot);
|
|
82
|
-
try {
|
|
83
|
-
const data = await readFile(local);
|
|
84
|
-
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
85
|
-
.send(data);
|
|
86
|
-
} catch {
|
|
87
|
-
fallback(err, 404);
|
|
88
|
-
}
|
|
89
58
|
});
|
|
90
59
|
};
|