@common-stack/frontend-stack-react 4.0.1-alpha.31 → 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};
|
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": {
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"typescript": {
|
|
51
51
|
"definition": "lib/index.d.ts"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5c696283f6ec69e7197c4593ea425a06b30bb7d4"
|
|
54
54
|
}
|