I already have an app written in MERN stack with koa server prepared build version. My main node file to run by node server.js
command to start the whole app looks like this.
In every tutorial, I see that I need to add functions.https.request
etc. in the beginning of coding (or at least to suppose doing it).
How could I host my app on firebase the same as I could on heroku - with whole server side?
You can run an express application using firebase hosting to serve dynamic content via firebase functions. You cannot, however, use Koa.js currently. The
functions.https.onRequest
requires you to pass an HTTP request handler or an express app returned fromexpress()
.Here is the relevant article from Firebase about serving dynamic content from functions. https://firebase.google.com/docs/hosting/functions
Here is a video tutorial from Firebase on using express. https://www.youtube.com/watch?v=LOeioOKUKI8
You can actually skip the listen call entirely, and use
app.callback()
. This seems to make more sense than listening on a random port that never actually gets hit.You can't deploy and run an arbitrary node app on Cloud Functions. You have to make use of the different types of triggers that are defined by the product.
See the Cloud Functions for Firebase main page to see the list.
Actual, it is possible to host
Koa
app using firebase functions, I figure it out after some heavy Googling and analyzing.This is a piece of code from my project, it is now hosted with firebase functions:
You can see the docs and tutorial video for more information.
By the way, here is another example to deploy Koa to
now.sh
version 2.