@common-stack/frontend-stack-react 4.0.1-alpha.29 → 4.0.1-alpha.32
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.
|
@@ -12,61 +12,65 @@ const containerMiddleware = async (req, res, next) => {
|
|
|
12
12
|
console.time(`Request ${requestId} Duration`); // Start timing the request
|
|
13
13
|
}
|
|
14
14
|
logger.debug(`Express req started - ID: ${requestId} , URL: ${req.url}`); // Log when request starts with unique ID
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
15
|
+
try {
|
|
16
|
+
const container = features.createContainers({}, requestId);
|
|
17
|
+
const clientState = features.getStateParams({
|
|
18
|
+
scopeId: requestId,
|
|
19
|
+
requestResponsePair: {
|
|
20
|
+
req,
|
|
21
|
+
res,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const { apolloClient } = createApolloClient({
|
|
25
|
+
httpGraphqlURL: config.GRAPHQL_URL,
|
|
26
|
+
httpLocalGraphqlURL: config.LOCAL_GRAPHQL_URL,
|
|
27
|
+
isDev: process.env.NODE_ENV === 'development',
|
|
28
|
+
isDebug: __DEBUGGING__,
|
|
29
|
+
isSSR: __SSR__,
|
|
30
|
+
scope: typeof window !== 'undefined' ? 'browser' : 'server',
|
|
31
|
+
clientState,
|
|
32
|
+
getDataIdFromObject: (result) => features.getDataIdFromObject(result),
|
|
33
|
+
initialState: typeof window !== 'undefined' ? window?.__APOLLO_STATE__ : undefined,
|
|
34
|
+
logger,
|
|
35
|
+
});
|
|
36
|
+
container.bind(TYPES.HttpRequest).toConstantValue(req);
|
|
37
|
+
let count = 1;
|
|
38
|
+
container
|
|
39
|
+
.bind(ClientTypes.ApolloClientFactory)
|
|
40
|
+
.toDynamicValue((context) => () => {
|
|
41
|
+
count = count + 1;
|
|
42
|
+
logger.debug(`Apollo Client Factory called - Count: ${count}`);
|
|
43
|
+
return apolloClient;
|
|
44
|
+
})
|
|
45
|
+
.inRequestScope();
|
|
46
|
+
const services = merge({}, ...features.createServiceFunc.map((serviceFunc) => serviceFunc(container)));
|
|
47
|
+
const resolvers = features.getApolloResolvers(() => services);
|
|
48
|
+
apolloClient.setResolvers(resolvers);
|
|
49
|
+
const { store } = createReduxStore(apolloClient, services, container);
|
|
50
|
+
req.container = container;
|
|
51
|
+
req.apolloClient = container.get(ClientTypes.ApolloClientFactory)();
|
|
52
|
+
req.logger = logger;
|
|
53
|
+
req.store = store;
|
|
54
|
+
req.services = services;
|
|
55
|
+
res.on('finish', () => {
|
|
56
|
+
logger.debug(`Express req Finished! - ID: ${requestId}`); // Log when request finishes with unique ID
|
|
57
|
+
if (config.LOG_LEVEL === 'debug' || config.LOG_LEVEL === 'trace') {
|
|
58
|
+
console.timeEnd(`Request ${requestId} Duration`); // End timing and log the duration
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
ScopedContainer.remove(requestId);
|
|
62
|
+
req.apollClient = null;
|
|
63
|
+
req.services = null;
|
|
64
|
+
logger.debug(`Successfully cleaned up - ID: ${requestId}`);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
logger.error(`Error during container cleanup - ID: ${requestId}`, error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
next();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger.error(`Error processing request - ID: ${requestId}`, error);
|
|
74
|
+
next(error);
|
|
75
|
+
}
|
|
72
76
|
};export{TYPES,containerMiddleware};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import Redis from 'ioredis';
|
|
2
|
-
export declare function getRedisClient(): Redis;
|
|
1
|
+
import { Redis, Cluster } from 'ioredis';
|
|
2
|
+
export declare function getRedisClient(logger?: any): Redis | Cluster;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import Redis
|
|
2
|
-
function getRedisClient() {
|
|
1
|
+
import {Cluster,Redis}from'ioredis';import {config}from'./env-config.server.js';let redisClient;
|
|
2
|
+
function getRedisClient(logger) {
|
|
3
3
|
if (!redisClient) {
|
|
4
4
|
// Initialize Redis client if it doesn't exist
|
|
5
|
-
|
|
5
|
+
if (config.REDIS_CLUSTER_ENABLED) {
|
|
6
|
+
if (!config.REDIS_CLUSTER_URL) {
|
|
7
|
+
throw new Error(`No nodes defined for cluster, ${config.REDIS_CLUSTER_URL}`);
|
|
8
|
+
}
|
|
9
|
+
logger?.info('Setting Redis.Cluster connection');
|
|
10
|
+
redisClient = new Cluster(config.REDIS_CLUSTER_URL, this.opts);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
logger?.info('Setting Redis connection');
|
|
14
|
+
redisClient = new Redis(config.REDIS_URL || this.opts);
|
|
15
|
+
}
|
|
16
|
+
return redisClient;
|
|
6
17
|
}
|
|
7
18
|
return redisClient;
|
|
8
19
|
}export{getRedisClient};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import'reflect-metadata';import features from'./modules.js';import {getRedisClient}from'./config/redis-config.server.js';/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1
|
+
import'reflect-metadata';import {logger}from'@cdm-logger/server';import features from'./modules.js';import {getRedisClient}from'./config/redis-config.server.js';/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
const routeConfig = features.getConfiguredRoutes();
|
|
3
|
-
const redisClient = getRedisClient();
|
|
3
|
+
const redisClient = getRedisClient(logger);
|
|
4
4
|
const loadContext = async (req, res) => {
|
|
5
5
|
const { container, store, apolloClient, services, logger } = req;
|
|
6
6
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/frontend-stack-react",
|
|
3
|
-
"version": "4.0.1-alpha.
|
|
3
|
+
"version": "4.0.1-alpha.32",
|
|
4
4
|
"description": "Client Module for react app",
|
|
5
5
|
"homepage": "https://github.com/cdmbase/fullstack-pro#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"watch": "npm run build:lib:watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@common-stack/client-react": "4.0.1-alpha.
|
|
33
|
-
"@common-stack/core": "4.0.1-alpha.
|
|
32
|
+
"@common-stack/client-react": "4.0.1-alpha.31",
|
|
33
|
+
"@common-stack/core": "4.0.1-alpha.31"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"jest-fetch-mock": "^3.0.3",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"typescript": {
|
|
51
51
|
"definition": "lib/index.d.ts"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5c696283f6ec69e7197c4593ea425a06b30bb7d4"
|
|
54
54
|
}
|