Firebase functions implementation
See original GitHub issueHi Sean,
I want to start off by saying again how much I love this project and the simplicity of it, it just makes working on API’s so much easier, structured, predictable and consistent.
Now, for multiple reasons, I decided to stop building these live server apps and switched completely to the functions-based approach, more specifically firebase. Now coding these functions, even though it supports typescript out of the box, is a complete pain. There’s no decent support for middleware, wrapping functions, it is indeed possible to manually add middleware and use some express features but that isn’t a thing for callable functions.
Now I’d like to start working on something similar to overnightjs but for functions, at first, for firebase functions specifically.
The baseline concept is you’d have your controllers + child controllers and your basic decorators are @OnRequest
and @OnCall
in every class. The basic features to support would be middleware + wrappers for @OnRequest(<NAME>)
and just wrappers for @OnCall(<NAME>)
.
Now because these would be functions operating independently from each other, we’d also want to have some decorator for things to be initialized only for the function, for example, a mongoose db connection, which you wouldn’t necessarily want to configure globally for all your stuff, maybe this could be solved with the standard @Wrapper?
In index.ts you’d configure your global middleware + global async wrappers for '@OnCall and '@OnRequest
;
Now for the end result, let’s assume we have a controller called ‘Reports’ which has a child controller called ‘Jobs’ which has a function called ‘daily’; Your end function name would be a camelCase of that tree, such as: reportsJobsDaily
;
I was thinking instead of just making my own thing, I’d suggest we build it together as part of the @overnight project?
Let me know what you think, thanks.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
@Nefiron there’s no way to implement overnightjs into something like cloud functions due to their nature, unless you make your whole API 1 cloud function which I have some doubts on how efficient it might be/how it would work.
I have just published minutes ago a super-beta version of the ‘mini-framework’/helpers (idk what to call the thing really) I’m working on to write firebase functions in a more structured way. check the folder ‘sample-project’ – it should be quite good to get you started but if you have any questions feel free to post them in that repo and I’ll do my best to help.
If you want to contribute and grow the thing, let me know and I’ll add you to the team, good luck!
Link: https://github.com/decorfn/firebase
@Nefiron I know of the thing, of course, and easy scalability is always the strong point of Cloud Functions. But when it comes to actual performance, I haven’t actually ran any tests to compare things with a traditional server + express app and how that performance compares as you scale.
Until I do those tests, I’ll use common sense and assume that it performs decently once a function is ‘woke’, but there’s got to be some hard data aspect to back these assumptions up.