@common-stack/server-stack 7.1.1-alpha.9 → 7.2.1-alpha.2
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/lib/MainStackServer.cjs +101 -142
- package/lib/MainStackServer.cjs.map +1 -1
- package/lib/MainStackServer.d.ts +10 -5
- package/lib/MainStackServer.mjs +101 -142
- package/lib/MainStackServer.mjs.map +1 -1
- package/lib/StackServer.cjs +23 -66
- package/lib/StackServer.cjs.map +1 -1
- package/lib/StackServer.d.ts +4 -5
- package/lib/StackServer.mjs +23 -66
- package/lib/StackServer.mjs.map +1 -1
- package/lib/api/schema-builder.cjs +13 -12
- package/lib/api/schema-builder.cjs.map +1 -1
- package/lib/api/schema-builder.mjs +13 -12
- package/lib/api/schema-builder.mjs.map +1 -1
- package/lib/api/sub-graph-schema-builder.cjs +13 -15
- package/lib/api/sub-graph-schema-builder.cjs.map +1 -1
- package/lib/api/sub-graph-schema-builder.mjs +14 -16
- package/lib/api/sub-graph-schema-builder.mjs.map +1 -1
- package/lib/config/env-config.cjs +6 -0
- package/lib/config/env-config.cjs.map +1 -1
- package/lib/config/env-config.d.ts +6 -0
- package/lib/config/env-config.mjs +6 -0
- package/lib/config/env-config.mjs.map +1 -1
- package/lib/examples/tenant-feature-example.d.ts +13 -0
- package/lib/examples/tenant-feature-integration.d.ts +14 -0
- package/lib/features/multi-module-example.d.ts +17 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.mjs +1 -1
- package/lib/infrastructure/container-module.cjs +27 -0
- package/lib/infrastructure/container-module.cjs.map +1 -0
- package/lib/infrastructure/container-module.d.ts +3 -0
- package/lib/infrastructure/container-module.mjs +27 -0
- package/lib/infrastructure/container-module.mjs.map +1 -0
- package/lib/infrastructure/example-workflows.d.ts +16 -0
- package/lib/infrastructure/index.d.ts +5 -0
- package/lib/infrastructure/infrastructure-factory.cjs +127 -0
- package/lib/infrastructure/infrastructure-factory.cjs.map +1 -0
- package/lib/infrastructure/infrastructure-factory.d.ts +33 -0
- package/lib/infrastructure/infrastructure-factory.mjs +127 -0
- package/lib/infrastructure/infrastructure-factory.mjs.map +1 -0
- package/lib/infrastructure/inngest-factory.cjs +26 -0
- package/lib/infrastructure/inngest-factory.cjs.map +1 -0
- package/lib/infrastructure/inngest-factory.d.ts +8 -0
- package/lib/infrastructure/inngest-factory.mjs +26 -0
- package/lib/infrastructure/inngest-factory.mjs.map +1 -0
- package/lib/infrastructure/types.d.ts +28 -0
- package/lib/infrastructure/usage-examples.d.ts +9 -0
- package/lib/infrastructure/workflow-orchestrator.cjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.cjs.map +1 -0
- package/lib/infrastructure/workflow-orchestrator.d.ts +10 -0
- package/lib/infrastructure/workflow-orchestrator.mjs +59 -0
- package/lib/infrastructure/workflow-orchestrator.mjs.map +1 -0
- package/lib/inngest/client-id-generator.d.ts +29 -0
- package/lib/inngest/handler-factory.d.ts +18 -0
- package/lib/inngest/multi-module-functions.d.ts +133 -0
- package/lib/inngest/setup.cjs +38 -0
- package/lib/inngest/setup.cjs.map +1 -0
- package/lib/inngest/setup.d.ts +10 -0
- package/lib/inngest/setup.mjs +38 -0
- package/lib/inngest/setup.mjs.map +1 -0
- package/lib/interfaces/graphql-request-context.d.ts +5 -0
- package/lib/middleware/index.d.ts +5 -0
- package/lib/middleware/redis-client.cjs +18 -0
- package/lib/middleware/redis-client.cjs.map +1 -0
- package/lib/middleware/redis-client.d.ts +16 -0
- package/lib/middleware/redis-client.mjs +18 -0
- package/lib/middleware/redis-client.mjs.map +1 -0
- package/lib/plugins/responseCachePlugin.cjs +1 -2
- package/lib/plugins/responseCachePlugin.cjs.map +1 -1
- package/lib/plugins/responseCachePlugin.mjs +1 -2
- package/lib/plugins/responseCachePlugin.mjs.map +1 -1
- package/lib/servers/ExpressApp.cjs +7 -2
- package/lib/servers/ExpressApp.cjs.map +1 -1
- package/lib/servers/ExpressApp.d.ts +1 -1
- package/lib/servers/ExpressApp.mjs +7 -2
- package/lib/servers/ExpressApp.mjs.map +1 -1
- package/lib/servers/GraphqlServer.cjs +7 -2
- package/lib/servers/GraphqlServer.cjs.map +1 -1
- package/lib/servers/GraphqlServer.d.ts +8 -6
- package/lib/servers/GraphqlServer.mjs +7 -2
- package/lib/servers/GraphqlServer.mjs.map +1 -1
- package/lib/servers/mongodb-migration-update.d.ts +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/safe-model-factory.d.ts +18 -0
- package/package.json +10 -9
- package/lib/api/resolver.cjs +0 -12
- package/lib/api/resolver.cjs.map +0 -1
- package/lib/api/resolver.mjs +0 -12
- package/lib/api/resolver.mjs.map +0 -1
- package/lib/api/root-schema.graphqls.cjs +0 -2
- package/lib/api/root-schema.graphqls.cjs.map +0 -1
- package/lib/api/root-schema.graphqls.mjs +0 -2
- package/lib/api/root-schema.graphqls.mjs.map +0 -1
- package/lib/api/scalar.cjs +0 -16
- package/lib/api/scalar.cjs.map +0 -1
- package/lib/api/scalar.mjs +0 -16
- package/lib/api/scalar.mjs.map +0 -1
- package/lib/graphql/directives/index.cjs +0 -10
- package/lib/graphql/directives/index.cjs.map +0 -1
- package/lib/graphql/directives/index.d.ts +0 -7
- package/lib/graphql/directives/index.mjs +0 -10
- package/lib/graphql/directives/index.mjs.map +0 -1
- package/lib/graphql/index.d.ts +0 -2
- package/lib/graphql/schema/directives.graphql.cjs +0 -1
- package/lib/graphql/schema/directives.graphql.cjs.map +0 -1
- package/lib/graphql/schema/directives.graphql.mjs +0 -1
- package/lib/graphql/schema/directives.graphql.mjs.map +0 -1
- package/lib/graphql/schema/index.cjs +0 -1
- package/lib/graphql/schema/index.cjs.map +0 -1
- package/lib/graphql/schema/index.d.ts +0 -1
- package/lib/graphql/schema/index.mjs +0 -1
- package/lib/graphql/schema/index.mjs.map +0 -1
package/lib/MainStackServer.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
'use strict';var http=require('http'),server=require('@cdm-logger/server'),serverCore=require('@common-stack/server-core'),
|
|
1
|
+
'use strict';require('reflect-metadata');var http=require('http'),server=require('@cdm-logger/server'),serverCore=require('@common-stack/server-core'),_=require('lodash-es'),graphqlModule=require('@common-stack/graphql-api/lib/module.js'),ExpressApp=require('./servers/ExpressApp.cjs'),GraphqlServer=require('./servers/GraphqlServer.cjs'),envConfig=require('./config/env-config.cjs'),schemaBuilder=require('./api/schema-builder.cjs'),WebsocketMultipathUpdate=require('./servers/WebsocketMultipathUpdate.cjs'),migrations=require('./utils/migrations.cjs');require('graphql');var subGraphSchemaBuilder=require('./api/sub-graph-schema-builder.cjs'),setup=require('./inngest/setup.cjs');require('inversify'),require('@common-stack/core');var infrastructureFactory=require('./infrastructure/infrastructure-factory.cjs');require('inngest');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var http__namespace=/*#__PURE__*/_interopNamespaceDefault(http);/* eslint-disable import/namespace */
|
|
2
2
|
/* eslint-disable import/no-unresolved */
|
|
3
3
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
4
4
|
// version 08/25/2021
|
|
5
|
+
const graphqlApiFeature = graphqlModule.default ?? graphqlModule;
|
|
5
6
|
function startListening(port) {
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
7
8
|
const server = this;
|
|
@@ -9,18 +10,6 @@ function startListening(port) {
|
|
|
9
10
|
server.listen(port, resolve);
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
const infraModule = ({ broker, pubsub, mongoClient, logger, redisClient }) => new inversify.ContainerModule((bind) => {
|
|
13
|
-
bind('Logger').toConstantValue(logger);
|
|
14
|
-
bind(core.CommonType.LOGGER).toConstantValue(logger);
|
|
15
|
-
bind('Environment').toConstantValue(envConfig.config.NODE_ENV || 'development');
|
|
16
|
-
bind(core.CommonType.ENVIRONMENT).toConstantValue(envConfig.config.NODE_ENV || 'development');
|
|
17
|
-
bind('PubSub').toConstantValue(pubsub);
|
|
18
|
-
bind(core.CommonType.PUBSUB).toConstantValue(pubsub);
|
|
19
|
-
bind(core.CommonType.MOLECULER_BROKER).toConstantValue(broker);
|
|
20
|
-
bind(core.CommonType.REDIS_CLIENT).toConstantValue(redisClient);
|
|
21
|
-
bind('MoleculerBroker').toConstantValue(broker);
|
|
22
|
-
bind('MongoDBConnection').toConstantValue(mongoClient);
|
|
23
|
-
});
|
|
24
13
|
/**
|
|
25
14
|
* Controls the lifecycle of the Application Server
|
|
26
15
|
*
|
|
@@ -31,116 +20,84 @@ class MainStackServer {
|
|
|
31
20
|
httpServer;
|
|
32
21
|
app;
|
|
33
22
|
logger;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
infrastructureFactory;
|
|
24
|
+
mainServiceContext;
|
|
25
|
+
microserviceContext;
|
|
37
26
|
multiPathWebsocket;
|
|
38
|
-
serviceContainer;
|
|
39
|
-
microserviceContainer;
|
|
40
27
|
serverFeature;
|
|
41
28
|
settings;
|
|
42
29
|
options;
|
|
30
|
+
serviceBroker;
|
|
31
|
+
allModules;
|
|
43
32
|
constructor(feature, settings, options) {
|
|
44
33
|
this.serverFeature = feature;
|
|
45
34
|
this.settings = settings;
|
|
46
35
|
this.options = options;
|
|
47
36
|
this.logger = server.logger.child({ className: 'StackServer' });
|
|
37
|
+
this.infrastructureFactory = new infrastructureFactory.InfrastructureFactory(this.logger);
|
|
48
38
|
}
|
|
49
39
|
async initialize() {
|
|
50
40
|
this.logger.info('StackServer initializing');
|
|
51
|
-
//
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
moleculerInterNamespace.InterNamespaceMiddleware([
|
|
60
|
-
{
|
|
61
|
-
namespace: 'api-admin',
|
|
62
|
-
transporter: moleculer_config.default.transporter,
|
|
63
|
-
metrics: { enabled: false },
|
|
64
|
-
},
|
|
65
|
-
]),
|
|
66
|
-
],
|
|
67
|
-
started: async () => {
|
|
68
|
-
await this.serverFeature.preStart(this.serviceContainer);
|
|
69
|
-
if (envConfig.config.NODE_ENV === 'development') ;
|
|
70
|
-
try {
|
|
71
|
-
this.logger.info('Starting Migration');
|
|
72
|
-
await migrations.migrate(mongoClient, this.serviceContainer, this.logger);
|
|
73
|
-
this.logger.info('End Migration');
|
|
74
|
-
}
|
|
75
|
-
catch (e) {
|
|
76
|
-
this.logger.error('Error while running migrations', e);
|
|
77
|
-
this.logger.error(e.stack);
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
await this.serverFeature.postStart(this.serviceContainer);
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
this.logger.error('Error while running Post Start due to [%s]', e.message);
|
|
84
|
-
this.logger.error(e.stack);
|
|
85
|
-
}
|
|
86
|
-
// start DB migration
|
|
87
|
-
if (envConfig.config.NODE_ENV === 'development') ;
|
|
88
|
-
},
|
|
89
|
-
// created,
|
|
90
|
-
async created() {
|
|
91
|
-
return Promise.resolve();
|
|
92
|
-
},
|
|
93
|
-
});
|
|
41
|
+
// Initialize infrastructure factory
|
|
42
|
+
await this.infrastructureFactory.initialize();
|
|
43
|
+
// Create main service broker and container
|
|
44
|
+
this.mainServiceContext = await this.infrastructureFactory.createBrokerAndContainer(infrastructureFactory.InfrastructureFactory.createMainServiceConfig(), this.serverFeature, this.settings);
|
|
45
|
+
// Setup main service broker lifecycle
|
|
46
|
+
this.setupMainServiceBrokerLifecycle();
|
|
47
|
+
// Create microservice broker and container for development environment
|
|
48
|
+
// Reuse same allModules but allow separate container with proper bindings
|
|
94
49
|
if (envConfig.config.NODE_ENV === 'development') {
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
metrics: { enabled: false },
|
|
98
|
-
nodeID: 'node-broker-2',
|
|
99
|
-
started: async () => {
|
|
100
|
-
await this.serverFeature.microservicePreStart(this.microserviceContainer);
|
|
101
|
-
await this.serverFeature.microservicePostStart(this.microserviceContainer);
|
|
102
|
-
},
|
|
103
|
-
// created,
|
|
104
|
-
created: async () => Promise.resolve(),
|
|
105
|
-
});
|
|
50
|
+
this.microserviceContext = await this.infrastructureFactory.createBrokerAndContainer(infrastructureFactory.InfrastructureFactory.createDevelopmentMicroserviceConfig(), this.serverFeature, this.settings, this.mainServiceContext.allModules);
|
|
51
|
+
this.setupMicroserviceBrokerLifecycle();
|
|
106
52
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
53
|
+
// Build GraphQL schema and create service context
|
|
54
|
+
await this.setupGraphQLSchema();
|
|
55
|
+
// Initialize HTTP server and Express app
|
|
56
|
+
await this.setupHttpServer();
|
|
57
|
+
}
|
|
58
|
+
setupMainServiceBrokerLifecycle() {
|
|
59
|
+
const originalStart = this.mainServiceContext.broker.start.bind(this.mainServiceContext.broker);
|
|
60
|
+
this.mainServiceContext.broker.start = async () => {
|
|
61
|
+
await originalStart();
|
|
62
|
+
// Execute pre-start hooks
|
|
63
|
+
await this.serverFeature.preStart(this.mainServiceContext.container);
|
|
64
|
+
try {
|
|
65
|
+
this.logger.info('Starting Migration');
|
|
66
|
+
await migrations.migrate(this.mainServiceContext.context.mongoClient, this.mainServiceContext.container, this.logger);
|
|
67
|
+
this.logger.info('End Migration');
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
this.logger.error('Error while running migrations', e);
|
|
71
|
+
this.logger.error(e.stack);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await this.serverFeature.postStart(this.mainServiceContext.container);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
this.logger.error('Error while running Post Start due to [%s]', e.message);
|
|
78
|
+
this.logger.error(e.stack);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
setupMicroserviceBrokerLifecycle() {
|
|
83
|
+
if (!this.microserviceContext)
|
|
84
|
+
return;
|
|
85
|
+
const originalStart = this.microserviceContext.broker.start.bind(this.microserviceContext.broker);
|
|
86
|
+
this.microserviceContext.broker.start = async () => {
|
|
87
|
+
await originalStart();
|
|
88
|
+
await this.serverFeature.microservicePreStart(this.microserviceContext.container);
|
|
89
|
+
await this.serverFeature.microservicePostStart(this.microserviceContext.container);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async setupGraphQLSchema() {
|
|
93
|
+
const { context, container, allModules: baseModules } = this.mainServiceContext;
|
|
94
|
+
// Compose features using the proper Feature pattern
|
|
95
|
+
const allModules = new serverCore.Feature(this.mainServiceContext.allModules, graphqlApiFeature);
|
|
139
96
|
const Constructor = this?.options?.isSubGraph ? subGraphSchemaBuilder.SubGraphSchemaBuilder : schemaBuilder.GatewaySchemaBuilder;
|
|
140
97
|
const executableSchema = await new Constructor({
|
|
141
98
|
schema: allModules.schemas,
|
|
142
99
|
resolvers: allModules.createResolvers({
|
|
143
|
-
pubsub,
|
|
100
|
+
pubsub: context.pubsub,
|
|
144
101
|
logger: server.logger,
|
|
145
102
|
subscriptionID: `${this.settings.subTopic}`,
|
|
146
103
|
}),
|
|
@@ -150,53 +107,55 @@ class MainStackServer {
|
|
|
150
107
|
rules: allModules.rules,
|
|
151
108
|
logger: server.logger,
|
|
152
109
|
}).build();
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
110
|
+
// Use the existing singleton container
|
|
111
|
+
const serviceContainer = container;
|
|
112
|
+
// Initialize services once to avoid recreating containers on every request
|
|
113
|
+
await allModules.createService({
|
|
156
114
|
...this.settings,
|
|
157
|
-
mongoConnection: mongoClient,
|
|
115
|
+
mongoConnection: context.mongoClient,
|
|
158
116
|
});
|
|
117
|
+
// Pre-create the service context function to avoid recreating containers on every request
|
|
118
|
+
const serviceContextFunc = allModules.createServiceContext({
|
|
119
|
+
...this.settings,
|
|
120
|
+
mongoConnection: context.mongoClient,
|
|
121
|
+
});
|
|
122
|
+
// Create service broker interface
|
|
159
123
|
const serviceBroker = {
|
|
160
|
-
serviceContainer:
|
|
161
|
-
serviceContext:
|
|
124
|
+
serviceContainer: serviceContainer,
|
|
125
|
+
serviceContext: serviceContextFunc,
|
|
162
126
|
dataSource: allModules.createDataSource(),
|
|
163
127
|
defaultPreferences: allModules.createDefaultPreferences(),
|
|
164
128
|
createContext: async (req, res) => allModules.createContext(req, res),
|
|
165
129
|
logger: server.logger,
|
|
166
130
|
schema: executableSchema,
|
|
167
131
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this.microserviceContainer = await allModules.createHemeraContainers({
|
|
175
|
-
...this.settings,
|
|
176
|
-
mongoConnection: mongoClient,
|
|
177
|
-
});
|
|
178
|
-
allModules.loadClientMoleculerService({
|
|
179
|
-
broker: this.microserviceBroker,
|
|
180
|
-
container: this.microserviceContainer,
|
|
181
|
-
settings: this.settings,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
// initialize Servers
|
|
132
|
+
this.serviceBroker = serviceBroker;
|
|
133
|
+
this.allModules = allModules;
|
|
134
|
+
}
|
|
135
|
+
async setupHttpServer() {
|
|
136
|
+
const { context } = this.mainServiceContext;
|
|
137
|
+
// Initialize HTTP server and Express app
|
|
185
138
|
this.httpServer = http__namespace.createServer();
|
|
186
|
-
|
|
187
|
-
|
|
139
|
+
// Pass Redis client to expressApp so it can be attached at the very top of middleware stack
|
|
140
|
+
this.app = await ExpressApp.expressApp(this.allModules, this.serviceBroker, null, this.httpServer, context.redisClient);
|
|
141
|
+
// Register existing express middleware (Redis client middleware is already attached in expressApp)
|
|
142
|
+
this.allModules.registerExpressMiddleware(this.app, this.mainServiceContext.container);
|
|
143
|
+
// Setup Inngest functions
|
|
144
|
+
setup.setupInngestFunctions(this.allModules, this.app, this.mainServiceContext.container, this.logger);
|
|
188
145
|
this.httpServer.startListening = startListening.bind(this.httpServer);
|
|
189
146
|
this.httpServer.on('request', this.app);
|
|
190
147
|
this.httpServer.on('close', () => {
|
|
191
148
|
this.httpServer = undefined;
|
|
192
149
|
});
|
|
193
|
-
|
|
150
|
+
// Setup WebSocket if configured
|
|
151
|
+
const customWebsocket = this.allModules.getWebsocketConfig();
|
|
194
152
|
const customWebsocketEnable = !_.isEmpty(customWebsocket);
|
|
195
153
|
if (customWebsocketEnable) {
|
|
196
|
-
this.multiPathWebsocket = new WebsocketMultipathUpdate.WebsocketMultiPathServer(serviceBroker, redisClient, customWebsocket);
|
|
154
|
+
this.multiPathWebsocket = new WebsocketMultipathUpdate.WebsocketMultiPathServer(this.serviceBroker, context.redisClient, customWebsocket);
|
|
197
155
|
this.httpServer = this.multiPathWebsocket.httpServerUpgrade(this.httpServer);
|
|
198
156
|
}
|
|
199
|
-
|
|
157
|
+
// Setup GraphQL server
|
|
158
|
+
const graphqlServer = new GraphqlServer.GraphqlServer(this.app, this.httpServer, context.redisClient, this.serviceBroker, !customWebsocketEnable, this.allModules.apolloCacheKeyGenerator.bind(this.allModules), this.allModules.apolloInvalidateCacheKeyGenerator.bind(this.allModules), this.allModules.graphqlPlugins);
|
|
200
159
|
await graphqlServer.initialize();
|
|
201
160
|
this.app.use('/graphql', (req, res, next) => {
|
|
202
161
|
res.append('Access-Control-Allow-Credentials', JSON.stringify(true));
|
|
@@ -207,11 +166,11 @@ class MainStackServer {
|
|
|
207
166
|
});
|
|
208
167
|
}
|
|
209
168
|
async start() {
|
|
210
|
-
if (envConfig.config.NODE_ENV === 'development') {
|
|
211
|
-
await Promise.all([this.
|
|
169
|
+
if (envConfig.config.NODE_ENV === 'development' && this.microserviceContext) {
|
|
170
|
+
await Promise.all([this.mainServiceContext.broker.start(), this.microserviceContext.broker.start()]);
|
|
212
171
|
}
|
|
213
172
|
else {
|
|
214
|
-
await this.
|
|
173
|
+
await this.mainServiceContext.broker.start();
|
|
215
174
|
}
|
|
216
175
|
}
|
|
217
176
|
async cleanup() {
|
|
@@ -221,14 +180,14 @@ class MainStackServer {
|
|
|
221
180
|
if (this.httpServer) {
|
|
222
181
|
await this.httpServer.close();
|
|
223
182
|
}
|
|
224
|
-
if (this.
|
|
225
|
-
await this.
|
|
183
|
+
if (this.infrastructureFactory) {
|
|
184
|
+
await this.infrastructureFactory.cleanup();
|
|
226
185
|
}
|
|
227
|
-
if (this.
|
|
228
|
-
await this.
|
|
186
|
+
if (this.mainServiceContext?.broker) {
|
|
187
|
+
await this.mainServiceContext.broker.stop();
|
|
229
188
|
}
|
|
230
|
-
if (this.
|
|
231
|
-
await this.
|
|
189
|
+
if (this.microserviceContext?.broker) {
|
|
190
|
+
await this.microserviceContext.broker.stop();
|
|
232
191
|
}
|
|
233
192
|
}
|
|
234
193
|
}exports.MainStackServer=MainStackServer;//# sourceMappingURL=MainStackServer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainStackServer.cjs","sources":["../src/MainStackServer.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"MainStackServer.cjs","sources":["../src/MainStackServer.ts"],"sourcesContent":[null],"names":["serverLogger","InfrastructureFactory","config","migrate","Feature","SubGraphSchemaBuilder","GatewaySchemaBuilder","http","expressApp","setupInngestFunctions","isEmpty","WebsocketMultiPathServer","GraphqlServer"],"mappings":"+pCAAA;AACA;AACA;AACA;AAwBA,MAAM,iBAAiB,GA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
3
4
|
import { Feature as ServerFeature } from '@common-stack/server-core';
|
|
@@ -13,17 +14,21 @@ export declare class MainStackServer {
|
|
|
13
14
|
};
|
|
14
15
|
app: express.Express;
|
|
15
16
|
private logger;
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
17
|
+
private infrastructureFactory;
|
|
18
|
+
private mainServiceContext;
|
|
19
|
+
private microserviceContext;
|
|
19
20
|
private multiPathWebsocket;
|
|
20
|
-
private serviceContainer;
|
|
21
|
-
private microserviceContainer;
|
|
22
21
|
private serverFeature;
|
|
23
22
|
private settings;
|
|
24
23
|
private options;
|
|
24
|
+
private serviceBroker;
|
|
25
|
+
private allModules;
|
|
25
26
|
constructor(feature: ServerFeature, settings: any, options?: Record<string, unknown>);
|
|
26
27
|
initialize(): Promise<void>;
|
|
28
|
+
private setupMainServiceBrokerLifecycle;
|
|
29
|
+
private setupMicroserviceBrokerLifecycle;
|
|
30
|
+
private setupGraphQLSchema;
|
|
31
|
+
private setupHttpServer;
|
|
27
32
|
start(): Promise<void>;
|
|
28
33
|
cleanup(): Promise<void>;
|
|
29
34
|
}
|