hyperstackjs / hyperstack

The pragmatic app framework for builders 🐶
https://hyperstackjs.io
MIT License
385 stars 12 forks source link

[Bug]: Some initializers are not being called. #3

Closed correiarmjoao closed 1 year ago

correiarmjoao commented 1 year ago

What happened?

I have been doing some tests with hyperstack and realised that the initializers, beforeMiddleware, afterMiddleware, beforeControllers and afterControllers are not being called.

Before app and after app work as expected.

I haven't tested afterLogger and beforeWorkers yet.

From what I could see in the code it seems that the issue comes from the validations of the initializers object in createServer.

https://github.com/hyperstackjs/hyperstack/blob/829c843ba3141333283fc24b1b6b50ae37ab1d60/packages/hyperstack/src/controllers.ts#L22-L61

The initializers object has a key initializers inside.

https://github.com/hyperstackjs/hyperstack/blob/829c843ba3141333283fc24b1b6b50ae37ab1d60/packages/hyperstack/src/initializers.ts#L47-L49

I can make a pull request with a fix for it if you want.

What type of Operating System?

macOS

Steps to produce this issue.

Running the kitchensink example should reproduce the issue.
jondot commented 1 year ago

Yes, that's correct!.

Seems we need to fetch the inner initializers.initializers field and hand it over:

probably something like from:

  const initializers = store.initializers

to:

  const initializers = store.initializers?.initializers

I'll be happy to accept a PR. Let me know if you need any help

ChengaDev commented 1 year ago

@jondot fixed in this PR, I think this issue be closed