Search code examples
firebasearchitectureweb-hosting

Multiple hosted Websites with only one backend


I want to create several similar webshops and manage everything from one centralized place. I wouldn't program the backend myself as it would take a lot of time + I don't want to update the security regularly. I would also not take multiple ready-made template webistes, because it would cost a lot monthly.

So far the best solution I have found would be the following:

I would code the frontend myself with HTML, CSS, JS (+ maybe VueJS) and get the backend as service from Firebase.

Quesiton Nr.1: Have you any better idea?

Quesiton Nr.2: If this solution is ok, then: is it possible to manage multiple hosted websites with Firebase with one backend? I mean separate domain for each websites, but 1 database and generally only one backend for all webshops?


Solution

  • You can set up one or more Firebase Hosting sites in a single Firebase project. Since the sites are all in the same Firebase project, all the sites can access the other Firebase resources of the project.

    https://firebase.google.com/docs/hosting/multisites?authuser=0&hl=it#set_up_deploy_targets

    Basically you add a site from the Firebase Hosting console, for example "my-app.web.app".

    In the project directory use the following command:

    firebase target:apply hosting TARGET_NAME my-app
    

    The target name is only used to help you during the deployment, obviously choose it with a criterion.

    The .firebaserc file should look like this:

     ...
     "targets": {
        "your-project": {
          "hosting": {
            "TARGET_NAME": [
              "my-app"
            ]
          }
        }
      }
      ...
    

    In the firebase.json file you have to transform the "hosting" field into an array and add, in addition to the already existing target, the new one.

    ...
    "hosting": [
        ...
        {
          "target": "TARGET_NAME",
          "public": "custom_dist",
          "ignore": [...],
          "rewrites": [...]
        }
      ]
    ...
    

    At this point to deploy, just use the following command:

    firebase deploy --only hosting:TARGET_NAME