使用Zeit-now部署后端

我正在尝试使用Zeit部署后端:

now命令

  1. 我有一个MongoDB数据库(位于mongoDB Atlas上)
  2. 我使用以下方式将连接字符串URL保存为secret

    now secrets add secret-name mongodb+srv://username:<password>@cluster0-7c8ma.mongodb.net/test?retryWrites=true&w=majority

  3. 在我的代码中,我将数据库定义为环境变量:

    const db = monk(process.env.DBName)

  4. 然后在部署时我使用了以下命令:

    now -e DBName=@secret-name

  5. 期望它在部署后连接到我在Atlas上的数据库

但是,相反,在部署时,我从.sh获得的now URL只是一个写有我的代码的网页。为什么这样做而不是在json中显示我的数据库?

asdsasdsaffff 回答:使用Zeit-now部署后端

结果是我的now.json文件配置不正确。 Zeit现在自动“假设我的文件是静态文件而不是node.js项目”-CJ Coding Garden

{
    "name": "valorantlfgposts-db","version": 2,"builds": [
      {
        "src": "index.js","use": "@now/node-server"
      }
    ],"routes": [
      { "src": "/.*","dest": "/index.js" }
    ]
  }
本文链接:https://www.f2er.com/2482539.html

大家都在问