H
Hono3w ago
Jesse

Factory app creation

Hi, I'm building a backend using Hono and am splitting up my routes into groups, for example '/authors', and '/books'. Each group is written in a separate file and then imported to the main Hono app which will serve the app. Right now I have authentication middleware on the main app and in that middleware the "user" context is set so we can access the current user on the routes below, however since the "books" and "authors" sub-apps are imported to the main app from a different location they don't have access to the context set by the middleware in the main app. In the "books" app I want to be able to access the "user" context from the middleware. What is the recommended way of doing this? nb: It seems like createFactory().createApp() was the recommended way to do this, however this seems to be deprecated?
4 Replies
ambergristle
ambergristle3w ago
hey! what makes you say that Factory.createApp appears deprecated? you're correct that it's the recommended/optimal way to achieve your goal, and afaik it's still valid/in-use in fact, i believe that it recently lost the beta tag (in the docs). i'm pretty sure it's a newer feature moving towards stability rather than deprecation. but you can always double-check the releases/source
Jesse
JesseOP3w ago
hey thanks for the response! I checked the source code but was unable to find much, it definitely seems to be a newer feature though so deprecation is not plausible. Could be something wrong with my IDE. The factory doesn't seem to have the createApp method
No description
Jesse
JesseOP3w ago
Ignore the above, i was using an old version of Hono... 🤦‍♂️ Upgraded and everything works great now!
ambergristle
ambergristle3w ago
been there, lol

Did you find this page helpful?