Shortly Responsive

Solution retrospective
building out my backend api, next time I will probably build out the backend to work first instead of building out the design
What challenges did you encounter, and how did you overcome them?hosting the URL shortener was hard because it didn't want to work with my Node server and Vercel. Luckily, I did get it to work after some tinkering with my code and changing the way that I handled routing in Node.js.
What specific areas of your project would you like help with?Probably would like to know a more efficient way to handle getting the API call for the shortly link because building an entire node server for this might not be the most efficient way to build this.
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@markuslewin
Next actually supports creating those types of request handlers in the same project as the rest of the app. They're called Route Handlers. It'd look something like this:
// /src/app/api/shorten/route.ts export async function POST(request: Request) { const { url } = await request.json(); // todo: fetch(cleanuri) console.log("Shorten", { url }); return Response.json({ success: true, shortUrl: "<shortUrl>", originalUrl: url, }); } // In component: const response = await fetch("/api/shorten", ...)
You could also use the newer Server Actions. They're essentially functions that get compiled to server endpoints:
// /src/app/actions.ts "use server"; export const shorten = async (url: string) => { // todo: fetch(cleanuri) console.log("Shorten", { url }); return { success: true, shortUrl: "<shortUrl>", originalUrl: url, }; }; // In component: const result = await shorten(url);
Marked as helpful
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord