【问题标题】:How to deploy web app with nuxt firebase?如何使用 nuxt firebase 部署 Web 应用程序?
【发布时间】:2021-07-03 20:54:36
【问题描述】:

我已将 nuxt firebase 插件安装到我的网络应用程序中,当我在本地提供生成的文件夹 (dist) 时,它运行良好。但是当我将它部署到服务器时,我的网络应用程序甚至无法识别任何 nuxt firebase 命令并导致这样的错误。

我错过了配置还是什么?

这是获取令牌的代码

  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);
  }

【问题讨论】:

  • 请出示nuxt.config.js

标签: javascript firebase vue.js firebase-cloud-messaging nuxtjs


【解决方案1】:

不久前我遇到了类似的问题。仔细检查您的 firebase.json 文件。以确保在您使用 CLI 时将其设置为将所有内容重写为 index.html。它应该是这样的

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

如果这不起作用,您可以尝试从 nuxt.config.js 中删除 ServerMiddleware 并在其自己的模块中实现它,如 this answer 中所示

【讨论】:

  • 您给我的文档似乎没有使用 nuxt-firebase。我正在使用插件。但是我发现了另一个问题,是不是所有的firebase服务都需要部署在https上?
  • 你好,是的。我引用的文件是 firebase-cli 的一部分。如果您不使用 CLI,我仍然会验证 firebase 是否配置为重定向到 index.html,至于 HTTPS 要求,确实是正确的。一切都必须是带有 Firebase 的 HTTPS,我在这里找到了一个 S/O 帖子详细说明了这一点:stackoverflow.com/a/46204382/2073738
  • 我猜这是我的 https 问题。目前我使用的服务器是 http 仅用于开发。很快我将转向 https。谢谢你的回答!
猜你喜欢
  • 2019-10-22
  • 2021-07-15
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多