I have an app
which consists of services
that are registered async
.
First time before I use app
I want app to register all services
. I would want to somehow return a Promise
and only then
return specific service I need.
export function app() {
if (instance) return instance;
instance = express(feathers());
ORM.default.then((data) => {
setupServices();
instance.configure(initServices);
return instance; //this is needed before service usage
});
return instance;
}
export function service(name) {
return app().service(name);
}
Other file:
import { service } from '../app';
const teamService = service('team');
At the moment teamService is null
, as service register async and are not registered first time I import it.