"use client"; import { useState } from "react"; import axios from "axios"; import dotenv from "dotenv"; dotenv.config({ path: "./.env.local" }); export default function Home() { const [longUrl, setLongUrl] = useState(""); const [shortUrl, setShortUrl] = useState(""); const handleSubmit = async (e) => { e.preventDefault(); // Use the frontend domain as the base URL const baseURL = window.location.origin; try { const response = await axios.post( `${process.env.NEXT_PUBLIC_BACKEND_URL}/reduce/shorten`, { long_url: longUrl, base_url: baseURL, // Include the frontend domain in the request body }, ); setShortUrl(response.data.short_url); } catch (error) { console.error("Error shortening URL:", error); } }; return (

URL Shortener

setLongUrl(e.target.value)} className="border border-gray-300 rounded-lg p-3 text-gray-800 focus:outline-none focus:ring-2 focus:ring-blue-500" />
{shortUrl && (

Short URL:{" "} {shortUrl}

)}
); }