-
-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: combine services enterprise #6307
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,9 @@ export default async function getApp( | |
services: IUnleashServices, | ||
unleashSession?: RequestHandler, | ||
db?: Knex, | ||
): Promise<Application> { | ||
): Promise<{ app: Application; services: unknown; stores: unknown }> { | ||
let combinedServices = services; | ||
let combinedStores = stores; | ||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Getting worse: Complex Method Why does this problem occur?This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring. Read more. To ignore this warning click here. |
||
const app = express(); | ||
|
||
const baseUriPath = config.server.baseUriPath || ''; | ||
|
@@ -179,7 +181,11 @@ export default async function getApp( | |
); | ||
|
||
if (typeof config.preRouterHook === 'function') { | ||
config.preRouterHook(app, config, services, stores, db); | ||
const { services: enterpriseServices, stores: enterpriseStores } = | ||
config.preRouterHook(app, config, services, stores, db); | ||
|
||
combinedServices = enterpriseServices; | ||
combinedStores = enterpriseStores; | ||
Comment on lines
+184
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do this? I think the "beauty" of the getApp method is that it just return an app, and the preHook just modifies it If we have to do that, I wouldn't call them enterpriseServices, I'd do something like: const { services: extendedServices, stores: extendedStores } =
config.preRouterHook(app, config, services, stores, db); |
||
} | ||
|
||
// Setup API routes | ||
|
@@ -212,5 +218,5 @@ export default async function getApp( | |
res.send(indexHTML); | ||
}); | ||
|
||
return app; | ||
return { app, stores: combinedStores, services: combinedServices }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { | |
RoleName, | ||
CustomAuthHandler, | ||
SYSTEM_USER, | ||
IUnleashStores, | ||
} from './types'; | ||
|
||
import User, { IUser } from './types/user'; | ||
|
@@ -68,7 +69,11 @@ async function createApp( | |
const secret = await stores.settingStore.get<string>('unleash.secret'); | ||
config.server.secret = secret!; | ||
} | ||
const app = await getApp(config, stores, services, unleashSession, db); | ||
const { | ||
app, | ||
services: combinedServices, | ||
stores: combinedStores, | ||
} = await getApp(config, stores, services, unleashSession, db); | ||
Comment on lines
+72
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Getting worse: Complex Method Why does this problem occur?This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring. Read more. To ignore this warning click here. |
||
|
||
await metricsMonitor.startMonitoring( | ||
config, | ||
|
@@ -80,9 +85,9 @@ async function createApp( | |
db, | ||
); | ||
const unleash: Omit<IUnleash, 'stop'> = { | ||
stores, | ||
stores: combinedStores as IUnleashStores, | ||
eventBus: config.eventBus, | ||
services, | ||
services: combinedServices as IUnleashServices, | ||
app, | ||
config, | ||
version: serverVersion, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have these as parametric types? Something like
<EServices extends IUnleashServices, EStores extends IUnleashStores>