使用 Zeit-now 部署后端

Deploying back-end with 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 上的数据库

但是,当它被部署时,我从 now 获得的 .sh URL 只是一个写有我的代码的网页。它这样做而不是在 json 中显示我的数据库的任何原因?

原来我的 now.json 文件配置不正确。 Zeit 现在自动 "assuming that my file was a static file instead of a node.js project" - CJ Coding Garden

{
    "name": "valorantlfgposts-db",
    "version": 2,
    "builds": [
      {
        "src": "index.js",
        "use": "@now/node-server"
      }
    ],
    "routes": [
      { "src": "/.*", "dest": "/index.js" }
    ]
  }