cloudcommerce 0.0.100 → 0.0.102
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 +15 -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/config/firebase.json +1 -10
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/lib/config.d.ts +3 -0
- package/packages/firebase/lib/config.js +9 -1
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/firebase/src/config.ts +13 -1
- package/packages/modules/lib/firebase.js +1 -1
- package/packages/modules/lib/firebase.js.map +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/modules/src/firebase.ts +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/lib/firebase/serve-storefront.js +18 -22
- package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -1
- package/packages/ssr/lib/firebase.js +17 -11
- package/packages/ssr/lib/firebase.js.map +1 -1
- package/packages/ssr/package.json +1 -2
- package/packages/ssr/src/firebase/serve-storefront.ts +19 -23
- package/packages/ssr/src/firebase.ts +20 -11
- package/packages/storefront/package.json +1 -1
- package/packages/types/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
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.102](https://github.com/ecomplus/cloud-commerce/compare/v0.0.101...v0.0.102) (2022-09-27)
|
|
6
|
+
|
|
7
|
+
### [0.0.101](https://github.com/ecomplus/cloud-commerce/compare/v0.0.100...v0.0.101) (2022-09-27)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **firebase:** Get additional deploy options from `process.env` ([b6c38e3](https://github.com/ecomplus/cloud-commerce/commit/b6c38e309fea94bf27eadc2f03ca697c73f56360))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **firebase:** Update config `httpsFunctionOptions` type def with optional props ([ff91e72](https://github.com/ecomplus/cloud-commerce/commit/ff91e723a919f2e0d6369da7a2f904691a619bab))
|
|
18
|
+
* **modules:** Trying default deloy options with concurrency 12 ([5052ac6](https://github.com/ecomplus/cloud-commerce/commit/5052ac6b6c93b18d2979c39d5f88cf6c458b5794))
|
|
19
|
+
|
|
5
20
|
### [0.0.100](https://github.com/ecomplus/cloud-commerce/compare/v0.0.99...v0.0.100) (2022-09-27)
|
|
6
21
|
|
|
7
22
|
|
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.102",
|
|
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>",
|
|
@@ -27,16 +27,7 @@
|
|
|
27
27
|
{
|
|
28
28
|
"predeploy": "npm --prefix \"$RESOURCE_DIR/storefront\" run build && npm run build -- --codebase ssr",
|
|
29
29
|
"source": "functions/ssr",
|
|
30
|
-
"codebase": "ssr"
|
|
31
|
-
"ignore": [
|
|
32
|
-
"storefront/!(dist|content|public)/**",
|
|
33
|
-
"storefront/dist/client/**",
|
|
34
|
-
"storefront/*",
|
|
35
|
-
"functions/ssr/storefront/!(dist|content|public)/**",
|
|
36
|
-
"functions/ssr/storefront/dist/client/**",
|
|
37
|
-
"functions/ssr/storefront/*",
|
|
38
|
-
"**/*.ts"
|
|
39
|
-
]
|
|
30
|
+
"codebase": "ssr"
|
|
40
31
|
}
|
|
41
32
|
],
|
|
42
33
|
"hosting": {
|
|
@@ -6,10 +6,18 @@ const tinyErpEvents = [
|
|
|
6
6
|
'products-priceSet',
|
|
7
7
|
'applications-dataSet',
|
|
8
8
|
];
|
|
9
|
+
const {
|
|
10
|
+
DEPLOY_REGION, DEPLOY_MEMORY, DEPLOY_TIMEOUT_SECONDS, DEPLOY_MIN_INSTANCES,
|
|
11
|
+
} = process.env;
|
|
9
12
|
const mergeConfig = {
|
|
10
13
|
hello: 'from @cloudcommerce/firebase',
|
|
11
14
|
httpsFunctionOptions: {
|
|
12
|
-
region:
|
|
15
|
+
region: DEPLOY_REGION || 'southamerica-east1',
|
|
16
|
+
memory: DEPLOY_MEMORY,
|
|
17
|
+
timeoutSeconds: DEPLOY_TIMEOUT_SECONDS
|
|
18
|
+
? Number(DEPLOY_TIMEOUT_SECONDS) : undefined,
|
|
19
|
+
minInstances: DEPLOY_MIN_INSTANCES
|
|
20
|
+
? Number(DEPLOY_MIN_INSTANCES) : undefined,
|
|
13
21
|
},
|
|
14
22
|
apps: {
|
|
15
23
|
discounts: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,MAAsB,MAAM,uBAAuB,CAAC;AAE3D,MAAM,aAAa,GAAmB;IACpC,qBAAqB;IACrB,cAAc;IACd,mBAAmB;IACnB,sBAAsB;CACvB,CAAC;AAEF,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,8BAA8B;IACrC,oBAAoB,EAAE;QACpB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,MAAsB,MAAM,uBAAuB,CAAC;AAE3D,MAAM,aAAa,GAAmB;IACpC,qBAAqB;IACrB,cAAc;IACd,mBAAmB;IACnB,sBAAsB;CACvB,CAAC;AAEF,MAAM,EACJ,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,oBAAoB,GACrB,GAAG,OAAO,CAAC,GAAG,CAAC;AAEhB,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,8BAA8B;IACrC,oBAAoB,EAAE;QACpB,MAAM,EAAE,aAAa,IAAI,oBAAoB;QAC7C,MAAM,EAAE,aAAoE;QAC5E,cAAc,EAAE,sBAAsB;YACpC,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,SAAS;QAC9C,YAAY,EAAE,oBAAoB;YAChC,CAAC,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,SAAS;KAC7C;IACD,IAAI,EAAE;QACJ,SAAS,EAAE;YACT,KAAK,EAAE,IAAI;SACZ;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,IAAI;SACZ;QACD,cAAc,EAAE;YACd,KAAK,EAAE,IAAI;SACZ;QACD,MAAM,EAAE;YACN,KAAK,EAAE,IAAI;SACZ;QACD,OAAO,EAAE;YACP,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,aAAa;SACtB;KACF;CACF,CAAC;AACF,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAExB,eAAe,MAId,CAAC"}
|
|
@@ -8,10 +8,22 @@ const tinyErpEvents: ApiEventName[] = [
|
|
|
8
8
|
'applications-dataSet',
|
|
9
9
|
];
|
|
10
10
|
|
|
11
|
+
const {
|
|
12
|
+
DEPLOY_REGION,
|
|
13
|
+
DEPLOY_MEMORY,
|
|
14
|
+
DEPLOY_TIMEOUT_SECONDS,
|
|
15
|
+
DEPLOY_MIN_INSTANCES,
|
|
16
|
+
} = process.env;
|
|
17
|
+
|
|
11
18
|
const mergeConfig = {
|
|
12
19
|
hello: 'from @cloudcommerce/firebase',
|
|
13
20
|
httpsFunctionOptions: {
|
|
14
|
-
region:
|
|
21
|
+
region: DEPLOY_REGION || 'southamerica-east1',
|
|
22
|
+
memory: DEPLOY_MEMORY as '128MiB' | '256MiB' | '512MiB' | '1GiB' | undefined,
|
|
23
|
+
timeoutSeconds: DEPLOY_TIMEOUT_SECONDS
|
|
24
|
+
? Number(DEPLOY_TIMEOUT_SECONDS) : undefined,
|
|
25
|
+
minInstances: DEPLOY_MIN_INSTANCES
|
|
26
|
+
? Number(DEPLOY_MIN_INSTANCES) : undefined,
|
|
15
27
|
},
|
|
16
28
|
apps: {
|
|
17
29
|
discounts: {
|
|
@@ -8,7 +8,7 @@ import serveModulesApi from './firebase/serve-modules-api.js';
|
|
|
8
8
|
const { httpsFunctionOptions } = config.get();
|
|
9
9
|
|
|
10
10
|
export const modules = onRequest({
|
|
11
|
-
concurrency:
|
|
11
|
+
concurrency: 12,
|
|
12
12
|
...httpsFunctionOptions,
|
|
13
13
|
}, (req, res) => {
|
|
14
14
|
serveModulesApi(req, res);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAE3D,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;AAE9C,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAE3D,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;AAE9C,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,EAAE;IACf,GAAG,oBAAoB;CACxB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACd,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
|
@@ -8,7 +8,7 @@ import serveModulesApi from './firebase/serve-modules-api';
|
|
|
8
8
|
const { httpsFunctionOptions } = config.get();
|
|
9
9
|
|
|
10
10
|
export const modules = onRequest({
|
|
11
|
-
concurrency:
|
|
11
|
+
concurrency: 12,
|
|
12
12
|
...httpsFunctionOptions,
|
|
13
13
|
}, (req, res) => {
|
|
14
14
|
serveModulesApi(req, res);
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { join as joinPath } from 'path';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
|
-
import compression from 'compression';
|
|
4
3
|
|
|
5
4
|
const { STOREFRONT_BASE_DIR } = process.env;
|
|
6
5
|
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
7
6
|
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
8
|
-
const compress = compression();
|
|
9
7
|
|
|
10
8
|
export default (req, res) => {
|
|
11
9
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
@@ -27,27 +25,25 @@ export default (req, res) => {
|
|
|
27
25
|
.send(err.toString());
|
|
28
26
|
}
|
|
29
27
|
};
|
|
30
|
-
compress(req, res, async () => {
|
|
31
28
|
/*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
29
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
30
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
31
|
+
global.ssr_handler = ssrHandler;
|
|
32
|
+
*/
|
|
33
|
+
global.ssr_handler(req, res, async (err) => {
|
|
34
|
+
if (err) {
|
|
35
|
+
res.set('X-SSR-Error', err.message);
|
|
36
|
+
fallback(err);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
40
|
+
try {
|
|
41
|
+
const data = await readFile(local);
|
|
42
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
43
|
+
.send(data);
|
|
44
|
+
} catch {
|
|
45
|
+
fallback(err, 404);
|
|
46
|
+
}
|
|
51
47
|
});
|
|
52
48
|
};
|
|
53
49
|
// # sourceMappingURL=serve-storefront.js.map
|
|
@@ -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;
|
|
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,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;AAE/E,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,GAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE;QAC1C,IAAI,GAAG,KAAK,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;YAC3E,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,CAAC;iBAC7C,IAAI,CAAC,cAAc;kBAChB,yCAAyC;kBACvC,wBAAwB,MAAM,QAAQ,kBAAkB,CAAC,GAAG,CAAC,KAAK;kBACpE,gBAAgB,GAAG,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;SACvD;aAAM;YACL,iBAAiB,CAAC,MAAM,EAAE,mCAAmC,CAAC;iBAC3D,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;SACzB;IACH,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"}
|
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
/* eslint-disable import/
|
|
1
|
+
/* eslint-disable import/no-unresolved, import/first */
|
|
2
2
|
import '@cloudcommerce/api/fetch-polyfill';
|
|
3
3
|
import { initializeApp } from 'firebase-admin/app';
|
|
4
4
|
|
|
5
5
|
initializeApp();
|
|
6
|
-
import
|
|
6
|
+
import functions from 'firebase-functions';
|
|
7
7
|
import config from '@cloudcommerce/firebase/lib/config';
|
|
8
8
|
import serveStorefront from './firebase/serve-storefront.js';
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
httpsFunctionOptions: {
|
|
12
|
+
region, timeoutSeconds, memory, minInstances,
|
|
13
|
+
},
|
|
14
|
+
} = config.get();
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})
|
|
16
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
17
|
+
export const ssr = functions
|
|
18
|
+
.region(region)
|
|
19
|
+
.runWith({
|
|
20
|
+
timeoutSeconds: timeoutSeconds || 15,
|
|
21
|
+
memory: memory ? memory.replace('i', '') : '256MB',
|
|
22
|
+
minInstances: minInstances || 1,
|
|
23
|
+
}).https.onRequest((req, res) => {
|
|
24
|
+
serveStorefront(req, res);
|
|
25
|
+
});
|
|
20
26
|
// # sourceMappingURL=firebase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,aAAa,EAAE,CAAC;AAEhB,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D,MAAM,EACJ,oBAAoB,EAAE,EACpB,MAAM,EACN,cAAc,EACd,MAAM,EACN,YAAY,GACb,GACF,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;AAEjB,wDAAwD;AACxD,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS;KACzB,MAAM,CAAC,MAAM,CAAC;KACd,OAAO,CAAC;IACP,cAAc,EAAE,cAAc,IAAI,EAAE;IACpC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAY,CAAC,CAAC,CAAC,OAAO;IAC7D,YAAY,EAAE,YAAY,IAAI,CAAC;CAChC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9B,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.102",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront SSR",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"@cloudcommerce/firebase": "workspace:*",
|
|
29
29
|
"@ecomplus/utils": "^1.4.1",
|
|
30
30
|
"color": "^4.2.3",
|
|
31
|
-
"compression": "^1.7.4",
|
|
32
31
|
"firebase-admin": "^11.0.1",
|
|
33
32
|
"firebase-functions": "^3.24.0",
|
|
34
33
|
"html-escaper": "^3.0.3",
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { Request, Response } from 'firebase-functions';
|
|
2
2
|
import { join as joinPath } from 'path';
|
|
3
3
|
import { readFile } from 'fs/promises';
|
|
4
|
-
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);
|
|
9
|
-
const compress = compression();
|
|
10
8
|
|
|
11
9
|
export default (req: Request, res: Response) => {
|
|
12
10
|
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
@@ -34,26 +32,24 @@ export default (req: Request, res: Response) => {
|
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
});
|
|
35
|
+
/*
|
|
36
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
37
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
38
|
+
global.ssr_handler = ssrHandler;
|
|
39
|
+
*/
|
|
40
|
+
global.ssr_handler(req, res, async (err: any) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
res.set('X-SSR-Error', err.message);
|
|
43
|
+
fallback(err);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
47
|
+
try {
|
|
48
|
+
const data = await readFile(local);
|
|
49
|
+
setStatusAndCache(200, 'public, max-age=60, s-maxage=600')
|
|
50
|
+
.send(data);
|
|
51
|
+
} catch {
|
|
52
|
+
fallback(err, 404);
|
|
53
|
+
}
|
|
58
54
|
});
|
|
59
55
|
};
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
/* eslint-disable import/
|
|
1
|
+
/* eslint-disable import/no-unresolved, import/first */
|
|
2
2
|
import '@cloudcommerce/api/fetch-polyfill';
|
|
3
3
|
import { initializeApp } from 'firebase-admin/app';
|
|
4
4
|
|
|
5
5
|
initializeApp();
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import functions from 'firebase-functions';
|
|
8
8
|
import config from '@cloudcommerce/firebase/lib/config';
|
|
9
9
|
import serveStorefront from './firebase/serve-storefront';
|
|
10
10
|
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
httpsFunctionOptions: {
|
|
13
|
+
region,
|
|
14
|
+
timeoutSeconds,
|
|
15
|
+
memory,
|
|
16
|
+
minInstances,
|
|
17
|
+
},
|
|
18
|
+
} = config.get();
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
20
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
21
|
+
export const ssr = functions
|
|
22
|
+
.region(region)
|
|
23
|
+
.runWith({
|
|
24
|
+
timeoutSeconds: timeoutSeconds || 15,
|
|
25
|
+
memory: memory ? memory.replace('i', '') as '256MB' : '256MB',
|
|
26
|
+
minInstances: minInstances || 1,
|
|
27
|
+
}).https.onRequest((req, res) => {
|
|
28
|
+
serveStorefront(req, res);
|
|
29
|
+
});
|