'Webapp front-end structure using Firebase, Hosting vs Functions [closed]

I'm working on a small scale ERP using Firebase's free plan (for a single user). I started out hard-coding html and serving it with firebase hosting, a flow that proved uneffective in the long run. Soon I needed routes, authentication and a database, which led me to using a Express server running in a single firebase function for everything, so I could protect the routes and database access. This gives me the feel I'm doing something terribly wrong as firebase functions has an obnoxiously long URL and my API routes are just one directory away from my front-end routes.

I'm at a loss to how I should proceed but I believe there are the following options:

  • A - Go back to using firebase hosting for the front-end, meaning I have to protect the static files with a function that checks localStorage for a web token (jwt) and redirects to the login page upon failure.
  • B - Create a second firebase function for the front-end, meaning I get to use ejs and express, but I have to keep the really long URL and I have no idea how to change it (using a redirect from an owned domain only serves as an alias, the domain name doesn't persist).

A seems unsafe and B annoys me as I don't get a custom URL, how should I proceed and serve the project?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source