Skip to content

Commit

Permalink
move routes and ioc init to startApi
Browse files Browse the repository at this point in the history
  • Loading branch information
rkamysz committed Jul 25, 2023
1 parent 9d6979b commit 5fb0e80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/api/api.dependencies.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<void>;
public routesProvider: (container: Container) => Route[];
public databaseConfigBuilder: DatabaseConfigBuilder;

public abstract initialize(
Expand Down
11 changes: 5 additions & 6 deletions src/api/start-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiCommandOptions>();
const config = buildApiConfig(vars, databaseConfigBuilder, options);
const routes = routesProvider(ioc);

await setupIoc(config, ioc);

api.setup(config);

Expand Down

0 comments on commit 5fb0e80

Please sign in to comment.