adrianhajdin / project_ai_mern_image_generation

Build and Deploy a Full Stack MERN AI Image Generation App MidJourney & DALL E Clone
https://jsmastery.pro
1.08k stars 302 forks source link

POST http://localhost:8080/api/v1/post 500 (Internal Server Error) #69

Closed Quinn-Kiwalabye closed 1 year ago

Quinn-Kiwalabye commented 1 year ago

help how do i fix this issue, the problem seems to be coming from postRoutes

`import express from 'express'; import * as dotenv from 'dotenv'; import { v2 as cloudinary } from 'cloudinary';

import Post from '../mongodb/models/post.js';

dotenv.config();

const router = express.Router();

cloudinary.config({ cloud_name: process.env.CLOUDINARY_CLOUD_NAME, api_key: process.env.CLOUDINARY_API_KEY, api_secret: process.env.CLOUDINARY_API_SECRET, });

router.route('/').get(async (req, res) => { try { const posts = await Post.find({}); res.status(200).json({ success: true, data: posts }); } catch (err) { res.status(500).json({ success: false, message: 'Fetching posts failed, please try again' }); } });

router.route('/').post(async (req, res) => { try { const { name, prompt, photo } = req.body; const photoUrl = await cloudinary.uploader.upload(photo);

const newPost = await Post.create({
  name,
  prompt,
  photo: photoUrl.url,
});

res.status(200).json({ success: true, data: newPost });

} catch (err) { res.status(500).json({ success: false, message: 'Unable to create a post, please try again' }); } });

export default router;`

spausum commented 1 year ago

Hey, how were you able to fix this issue?

Quinn-Kiwalabye commented 1 year ago

hey, i simply matched my package json with adrian's package json and the typed "npm install" and then the issue was fixed