Before you start
Check these off so you’re ready to ship.
Not today
Do not use GitHub Pages — this is a Next.js app, so the host is Vercel. Never commit .env. Search and login wait until the live URL works.
Cloudinary + upload route
- 1
Sign up at
cloudinary.com. Copy Cloud Name, API Key, and API Secret into.env. - 2
Run
npm install cloudinary. - 3
Create
app/api/upload/route.ts(not route.js) — receive a file, upload it, return{ url }.
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secretimport { v2 as cloudinary } from 'cloudinary';
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
export async function POST(request: Request) {
const formData = await request.formData();
const file = formData.get('file');
if (!(file instanceof File)) {
return Response.json({ error: 'No file' }, { status: 400 });
}
const buffer = Buffer.from(await file.arrayBuffer());
const result = await new Promise<{ secure_url: string }>((resolve, reject) => {
cloudinary.uploader.upload_stream(
{ folder: 'marketplace' },
(error, uploaded) => {
if (error || !uploaded) reject(error);
else resolve(uploaded);
}
).end(buffer);
});
return Response.json({ url: result.secure_url });
}Vercel has no folder for uploads. The app stores a URL, not a file.
Save and show the photo
- 1
In
app/api/listings/route.ts, readimageUrlfrom the body and pass it intoprisma.listing.create. Module 7 already made the column — you just have to write it. - 2
Update
ListingCardso it takes animageUrlprop and uses<img src={imageUrl} />instead of a hardcoded placeholder. - 3
On home (and detail if you show a photo there), pass
imageUrl={item.imageUrl}intoListingCard. - 4
On
app/post/page.tsx, addimageFilestate and a file input — that is whereimageFilecomes from. - 5
Inside
handleSubmit: if a file was chosen,POST /api/uploadfirst, thenPOST /api/listingswith that URL. If they skip the file, keep the placeholder.
export async function POST(request: Request) {
const body = await request.json();
const listing = await prisma.listing.create({
data: {
title: body.title,
description: body.description,
price: parseFloat(body.price),
imageUrl: body.imageUrl,
},
});
return Response.json(listing, { status: 201 });
}type CardProps = {
title: string;
price: number;
description: string;
imageUrl: string;
};
export default function ListingCard({ title, price, description, imageUrl }: CardProps) {
return (
<div>
<img src={imageUrl} alt={title} />
<h3>{title}</h3>
<p>₱{price}</p>
<p>{description}</p>
</div>
);
}<ListingCard
title={item.title}
price={item.price}
description={item.description}
imageUrl={item.imageUrl}
/>const [title, setTitle] = useState('');
const [price, setPrice] = useState('');
const [description, setDescription] = useState('');
const [imageFile, setImageFile] = useState<File | null>(null);
// inside the form, with title / price / description:
<label>
Photo (optional)
<input
type="file"
accept="image/*"
onChange={(e) => setImageFile(e.target.files?.[0] ?? null)}
/>
</label>async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
let imageUrl = 'https://placehold.co/300x200';
if (imageFile) {
const uploadData = new FormData();
uploadData.append('file', imageFile);
const uploadRes = await fetch('/api/upload', { method: 'POST', body: uploadData });
const uploadResult = await uploadRes.json();
imageUrl = uploadResult.url;
}
await fetch('/api/listings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, price, description, imageUrl }),
});
router.push('/');
}Order matters: upload → get url → save the listing. If the photo uploads but the card stays a placeholder, you forgot imageUrl on create or on ListingCard.
Check localhost + Prisma generate
- 1
Home and detail already call Prisma (Module 7). The form already uses relative
/api/listings. Both work on Vercel. - 2
Search the project for
localhost:3000. Delete anyfetch('http://localhost:3000/...'). - 3
Add
"postinstall": "prisma generate"inpackage.jsonso Vercel can build.
"scripts": {
"dev": "next dev",
"build": "next build",
"postinstall": "prisma generate"
}If the live home page is empty, you still hardcoded localhost — or you forgot DATABASE_URL on Vercel.
GitHub + Vercel
- 1
Run
git status—.envmust not be listed. Commit and push. - 2
Go to
vercel.com, sign in with GitHub, Import the repo. - 3
Paste
DATABASE_URLand the three Cloudinary variables before you click Deploy. - 4
Open the live URL on a laptop and on a phone. Post a listing with a photo. Refresh.
DATABASE_URL
CLOUDINARY_CLOUD_NAME
CLOUDINARY_API_KEY
CLOUDINARY_API_SECRETNo npm run dev on the phone. If classmates see your listing, you shipped.
Done checklist
Tick everything before you submit.
Submit
Turn in the live URL. GitHub Pages is the wrong host.
| Deliverable | What to turn in |
|---|---|
| Live site | Your Vercel URL |
| Repo | GitHub URL — without .env |
Final challenge: send the URL to one classmate and ask them to post. If you see their listing, the app works end to end.
Still posting only on localhost? Finish Module 7 first then come back.