Error Terminal #1
Error Terminal #2
It says ECONNREFUSED 127.0.0.1:3000 and same error occurs when I try to deploy the code to vercel. Never got this type of error, so not understanding why is it happening?
I tried many times but doesn’t work. But npm run dev works.
Next JS Version: 14.1.3
Error is given in the terminal screenshots.
My app/api/properties/route.js code:
import { getSessionUser } from "@/utils/getSessionUser";
import cloudinary from "@/config/cloudinary";
import { createProperty, getProperties } from "@/actions/dbActions";
// export const dynamic = "force-dynamic";
///Get /api/properties
export const GET = async (request) => {
try {
const page = request.nextUrl.searchParams.get("page") || 1;
const pageSize = request.nextUrl.searchParams.get("pageSize") || 6;
const { properties, total } = await getProperties(page, pageSize);
const result = {
total,
properties,
};
return new Response(JSON.stringify(result), {
status: 200,
});
} catch (error) {
console.error("Error fetching properties:", error);
return new Response("Something went wrong", { status: 500 });
}
};
//Post /api/properties
export const POST = async (request) => {
try {
const sessionUser = await getSessionUser();
if (!sessionUser || !sessionUser.userId) {
return new Response(JSON.stringify({ message: "User ID is required" }), {
status: 401,
});
}
const { userId } = sessionUser;
const formData = await request.formData();
// Access all values from amenities and images
const amenities = formData.getAll("amenities");
const images = formData
.getAll("images")
.filter((image) => image.name !== "");
// Create propertyData object for database
const propertyData = {
type: formData.get("type"),
name: formData.get("name"),
description: formData.get("description"),
location: {
street: formData.get("location.street"),
city: formData.get("location.city"),
state: formData.get("location.state"),
zipcode: formData.get("location.zipcode"),
},
beds: formData.get("beds"),
baths: formData.get("baths"),
square_feet: formData.get("square_feet"),
amenities,
rates: {
weekly: formData.get("rates.weekly"),
monthly: formData.get("rates.monthly"),
nightly: formData.get("rates.nightly."),
},
seller_info: {
name: formData.get("seller_info.name"),
email: formData.get("seller_info.email"),
phone: formData.get("seller_info.phone"),
},
owner: userId,
};
// Upload image(s) to Cloudinary
const imageUploadPromises = [];
for (const image of images) {
const imageBuffer = await image.arrayBuffer();
const imageArray = Array.from(new Uint8Array(imageBuffer));
const imageData = Buffer.from(imageArray);
// Convert the image data to base64
const imageBase64 = imageData.toString("base64");
// Make request to upload to Cloudinary
const result = await cloudinary.uploader.upload(
`data:image/png;base64,${imageBase64}`,
{
folder: "propertypulse",
}
);
imageUploadPromises.push(result.secure_url);
// Wait for all images to upload
const uploadedImages = await Promise.all(imageUploadPromises);
// Add uploaded images to the propertyData object
propertyData.images = uploadedImages;
}
const newProperty = await createProperty(propertyData);
return Response.redirect(
`${process.env.NEXTAUTH_URL}/properties/${newProperty._id}`
);
} catch (error) {
console.error("Error adding property:", error);
return new Response(JSON.stringify({ message: "Failed to add property" }), {
status: 500,
});
}
};