【问题标题】:Why my Vercel serverless functions not working in production?为什么我的 Vercel 无服务器功能在生产中不起作用?
【发布时间】:2021-08-02 15:53:15
【问题描述】:

您好,我在 Vercel 中部署应用程序时遇到问题,我正在创建一个没有服务器的函数,该函数使用 mongoose 在 mongodb 中为我带来集合的数据。在本地一切正常,但是当我部署该功能时,它给了我这个错误:

504: GATEWAY_TIMEOUT
Code: FUNCTION_INVOCATION_TIMEOUT
ID: gru1 :: 594vg-1620811347355-66f311d5c992

我了解 vercel 的免费计划允许您创建最多等待 10 秒的函数,这就是我收到错误的原因吗?或者可能是出于以下原因之一:https://vercel.com/support/articles/why-does-my-serverless-function-work-locally-but-not-when-deployed

无服务器功能:

import mongoose from "mongoose";
module.exports = function(req, res) {
  const Schema = mongoose.Schema;
  const inmuebleSchema = new Schema({
    user_id: String, //{type: Schema.Types.ObjectId, ref: 'User'}
    desc: String,
    tipo_propiedad: { type: String, enum: ["casa", "quinta", "departamento"] },
    amb: Number,
    estado: { type: String, enum: ["venta", "alquiler"] },
    banios: Number,
    dorm: Number,
    coch: Number,
    direc: String,
    precio: String,
    images: { type: Array, default: [] },
    uploadedDate: { type: Date, default: Date.now() }
  });
  const Inmueble = mongoose.model("inmueble", inmuebleSchema);
  mongoose
    .connect(process.env.MONGODB_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true
    })
    .then(() => {
      Inmueble.find()
        .exec()
        .then(inmuebles => res.json({ inmuebles }))
        .catch(err => res.json({ status: "error" }));
    })
    .catch(err => {
      res.status(500);
    });
};

【问题讨论】:

    标签: serverless vercel


    【解决方案1】:

    问题是,我没有将站点的 IP 添加到集群的白名单中。

    【讨论】:

      猜你喜欢
      • 2021-03-25
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      相关资源
      最近更新 更多