From 5fb0e809e60311dccc575eef062dd4bfd01048d8 Mon Sep 17 00:00:00 2001 From: rkamysz Date: Tue, 25 Jul 2023 13:34:01 +0200 Subject: [PATCH] move routes and ioc init to startApi --- src/api/api.dependencies.ts | 3 +++ src/api/start-api.ts | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/api.dependencies.ts b/src/api/api.dependencies.ts index 5615ef5..db32b7d 100644 --- a/src/api/api.dependencies.ts +++ b/src/api/api.dependencies.ts @@ -1,6 +1,7 @@ import { Container, Result, Route, UnknownObject } from '@alien-worlds/api-core'; import { DatabaseConfigBuilder, Dependencies } from '../common'; import { Api } from './api'; +import { ApiConfig } from './api.types'; /** * An abstract class representing a Api dependencies. @@ -9,6 +10,8 @@ import { Api } from './api'; export abstract class ApiDependencies extends Dependencies { public api: Api; public ioc: Container; + public setupIoc: (config: ApiConfig, container: Container) => Promise; + public routesProvider: (container: Container) => Route[]; public databaseConfigBuilder: DatabaseConfigBuilder; public abstract initialize( diff --git a/src/api/start-api.ts b/src/api/start-api.ts index 5465dd1..a4fe4c9 100644 --- a/src/api/start-api.ts +++ b/src/api/start-api.ts @@ -6,15 +6,14 @@ import { ApiCommandOptions } from './api.types'; import { buildApiConfig } from '../config'; import { ApiDependencies } from './api.dependencies'; -export const startApi = async ( - dependencies: ApiDependencies, - routes: Route[] = [], - ...args: string[] -) => { - const { api, databaseConfigBuilder } = dependencies; +export const startApi = async (dependencies: ApiDependencies, ...args: string[]) => { + const { api, ioc, databaseConfigBuilder, routesProvider, setupIoc } = dependencies; const vars = new ConfigVars(); const options = apiCommand.parse(args).opts(); const config = buildApiConfig(vars, databaseConfigBuilder, options); + const routes = routesProvider(ioc); + + await setupIoc(config, ioc); api.setup(config);