0

I have installed the nuxt firebase plugin into my web app and when I serve the generated folder (dist) locally, it runs perfectly. But when I deploy it to the server, my web app doesnt even recognize any nuxt firebase command and causes an error like this.

enter image description here

Did I miss a configuration or something?

Here is the code to get the token

  let currentToken;
  try {
    const permission = await Notification.requestPermission()
    currentToken = await this.$fire.messaging.getToken();
    //console.log(currentToken);
    this.model.DeviceToken = currentToken;
  } catch (e) {
    console.error('An error occurred while retrieving token. ', e);
  }

1 Answers1

1

I had a similar issue not too long ago. Double-check your firebase.json file. to ensure that when you are using the CLI it is set up to rewrite everything to index.html. It should look like this

{
  "hosting": {
    "public": "./dist",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html" <------
      }
    ]
  }
}

If that does not work you can try removing ServerMiddleware from nuxt.config.js and implementing it in its own module, as demonstrated in this answer

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
  • Also this article may be useful https://dev.to/kiritchoukc/deploy-nuxt-on-firebase-4ad8 – Marcello B. Apr 08 '21 at 04:21
  • it seems the doc that you have given me is not using nuxt-firebase. Im using the plugin. But i found another problem, is it true that all firebase service needed to be deployed on https? – ProgrammerTaiga Apr 08 '21 at 04:35
  • 1
    Hello, yes it would be. The file I am referencing is part of the firebase-cli. If you are not using the CLI, I would still verify that firebase is configured to redirect to `index.html`, As for the HTTPS requirement, that is indeed correct. Everything has to be HTTPS with firebase, I found a S/O post detailing this further here:https://stackoverflow.com/a/46204382/2073738 – Marcello B. Apr 08 '21 at 04:41
  • 1
    i guess thats my problem with the https. Currently the server that I am using is http for development only. Soon I will move to https. Thank you for the answer! – ProgrammerTaiga Apr 09 '21 at 02:03