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

Whenever I try to share API generated image to the home page, it gives me "POST http://localhost:8080/api/v1/post 500 (Internal Server Error) handleSubmit @ CreatePost.jsx:23" error even after giving "Success" alert. #58

Closed Atul240202 closed 1 year ago

Atul240202 commented 1 year ago

According to the above error "POST" request in handleSubmit is not working. But it is giving "Success" alert. I am really confuse about the error.

const handleSubmit = async (e) => { e.preventDefault();

if (form.prompt && form.photo) {
  setLoading(true);
  try {
    const response = await fetch('http://localhost:8080/api/v1/post', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ ...form }),
    });
    await response.json();
    alert('Success');
    navigate('/');
  } catch (error) {
    alert(error);
  } finally {
    setLoading(false);
  }
} else {
  alert('Please enter your prompt to generate your image');
}

};

ShadabImran07 commented 1 year ago

hey can you check your server index file and postRoutes file for me have same just replace with this code app.get("/", async (req, res) => { res.status(200).json({ message: "Hello from DALL.E!", }); }); and my error is solved

HarshAjayKothare commented 1 year ago

@ShadabImran07 what and where did you replace this, i cant understand plzx help

ShadabImran07 commented 1 year ago

In back-end file main index.js file