اذهب إلى المحتوى
  • 0

Heroku خطأ h13 timeout responce

أحمد عبد الله2

السؤال

هذا هو الايرور  مكتوب ومصور ايضا بعدما كتبت الامر   heroku logs --tail

erroe.thumb.png.efdc3331038f841435558eb7e3eeda97.png


بحثت وحاولت عن طرق لعلاجه وللكن لا فائدة 

جدير بالذكر ان التطبيق يعمل بشكل سليم تمام على Localhost بدون اى اخطاء ويعطينى ال 200 statuscode ايضا 
app.js

const express = require("express");
const mongoose = require("mongoose");
const morgan = require("morgan");
require("dotenv/config");
var cors = require("cors");

const app = express();

app.use(express.json());
app.use(morgan("tiny"));
app.use(cors());

const infractionRouter = require("./router/infractions");
app.use("/infractions", infractionRouter);

const catgRouter = require("./router/catg");
app.use("/catgs", catgRouter);

app.use("/public/uploads", express.static(__dirname + "/public/uploads"));

mongoose
  .connect(process.env.connect, {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    dbName: "MaiShakawy",
  })
  .then(console.log("coneected to database suuccessfully"))
  .catch((err) => console.log(err));

let port = process.env.PORT || 3000;

app.listen(port);

model

const mongoose = require("mongoose");

const InfractionSchema = mongoose.Schema({
  content: {
    type: String,
    required: true,
  },
  Catg: {
    type: mongoose.Schema.Types.ObjectId,
    required: true,
    ref: "Catg",
  },
  image: {
    type: String,
    default: "",
  },
});

exports.infractionModel = mongoose.model("Infraction", InfractionSchema);

router

const express = require("express");
const router = express.Router();
const { infractionModel } = require("../model/infraction");
const multer = require("multer");

const FILE_TYPE_MAP = {
  "image/png": "png",
  "image/jpeg": "jpeg",
  "image/jpg": "jpg",
};

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    const isValid = FILE_TYPE_MAP[file.mimetype];
    let uploadError = new Error("invalid tpye");
    if (isValid) {
      uploadError = null;
    }
    cb(uploadError, "public/uploads");
  },
  filename: function (req, file, cb) {
    const fileName = file.originalname.split(" ").join("-");
    const extension = FILE_TYPE_MAP[file.mimetype];
    cb(null, `${fileName}-${Date.now()}.${extension}`); // cb >>> callback
  },
});

const uploadOptions = multer({ storage: storage });

router.post("/", uploadOptions.single("image"), async (req, res) => {
  const fileName = req.file.filename;
  const basePath = `${req.protocol}://${req.get("host")}/public/uploads/`; // دا عشان نقدر نعمل عنوان زى اللى تحت دا

  let newInfraction = infractionModel({
    content: req.body.content,
    image: `${basePath}${fileName}`,
    Catg: req.body.Catg,
  });
  newInfraction = await newInfraction.save();
  res.send(newInfraction);
});

router.get("/", async (req, res) => {
  infractionList = await infractionModel.find().populate("Catg");
  res.send(infractionList);
});

module.exports = router;

env.

connect = mongodb+srv://trainer:a12345678@cluster0.f0bzw.mongodb.net/MaiShakawy?retryWrites=true&w=majority

package.json

{
  "name": "shakawy",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "engines": {
    "node": "15.14.0"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "mongoose": "^5.12.12",
    "morgan": "^1.10.0",
    "multer": "^1.4.2",
    "nodemon": "^2.0.7",
    "notenv": "^2.0.3"
  }
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

بالنظر للشيفرة والخطأ لا يمكن تحديد الخطأ بالشكل الدقيق لكن يمكن أن أشير لتعديلات ممكن أن تكون السبب 

  • يجب أن يكون هناك env variable PORT  في heroku
  • المجلد public/upload لا يوجد في المشروع
  • تأكد من أسماء المتغيرات env 
  • تأكد جيدا من رابط ال database
  • في ال router أنت تستخدم async await بدون try catch
  • try{
    infractionList = await infractionModel.find().populate("Catg");
      res.send(infractionList)
    }carch(err){
    
    res.status(400).json(err)
    }

     

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 8 دقائق مضت قال Salah Eddin Berriani:

بالنظر للشيفرة والخطأ لا يمكن تحديد الخطأ بالشكل الدقيق لكن يمكن أن أشير لتعديلات ممكن أن تكون السبب 

  • يجب أن يكون هناك env variable PORT  في heroku
  • المجلد public/upload لا يوجد في المشروع
  • تأكد من أسماء المتغيرات env 
  • تأكد جيدا من رابط ال database
  • في ال router أنت تستخدم async await بدون try catch
  • 
    try{
    infractionList = await infractionModel.find().populate("Catg");
      res.send(infractionList)
    }carch(err){
    
    res.status(400).json(err)
    }

     

لا المجلد موجود public/upload لكنى لم اضفه

وهل عدم استخدام try catch يؤثر على المشروع ؟

تم التعديل في بواسطة أحمد ابراهيم عبد الله
رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...