mirror of
https://github.com/arkorty/Reduce.git
synced 2026-03-18 00:47:10 +00:00
Initial commit
This commit is contained in:
22
frontend/app/api/redirect/[id]/route.js
Normal file
22
frontend/app/api/redirect/[id]/route.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import axios from "axios";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export async function GET(request, { params }) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/${id}`,
|
||||
);
|
||||
if (response.status === 200) {
|
||||
return NextResponse.redirect(response.data.long_url);
|
||||
} else {
|
||||
return new NextResponse("URL not found", { status: 404 });
|
||||
}
|
||||
} catch (error) {
|
||||
return new NextResponse("Server error", { status: 500 });
|
||||
}
|
||||
}
|
||||
BIN
frontend/app/favicon.ico
Normal file
BIN
frontend/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
33
frontend/app/globals.css
Normal file
33
frontend/app/globals.css
Normal file
@@ -0,0 +1,33 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 214, 219, 220;
|
||||
--background-end-rgb: 255, 255, 255;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--foreground-rgb: 255, 255, 255;
|
||||
--background-start-rgb: 0, 0, 0;
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
transparent,
|
||||
rgb(var(--background-end-rgb))
|
||||
)
|
||||
rgb(var(--background-start-rgb));
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.text-balance {
|
||||
text-wrap: balance;
|
||||
}
|
||||
}
|
||||
20
frontend/app/layout.js
Normal file
20
frontend/app/layout.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export const metadata = {
|
||||
title: "URL Shortener",
|
||||
description: "A simple URL shortener application",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={inter.className}>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
61
frontend/app/page.js
Normal file
61
frontend/app/page.js
Normal file
@@ -0,0 +1,61 @@
|
||||
"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();
|
||||
const response = await axios.post(
|
||||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/shorten`,
|
||||
{
|
||||
long_url: longUrl,
|
||||
},
|
||||
);
|
||||
setShortUrl(response.data.short_url);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500">
|
||||
<div className="bg-white p-8 rounded-lg shadow-lg max-w-md w-full">
|
||||
<h1 className="text-3xl font-bold mb-6 text-center text-gray-800">
|
||||
URL Shortener
|
||||
</h1>
|
||||
<form onSubmit={handleSubmit} className="flex flex-col space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter URL"
|
||||
value={longUrl}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-blue-500 text-white py-2 rounded-lg hover:bg-blue-600 transition duration-200"
|
||||
>
|
||||
Shorten
|
||||
</button>
|
||||
</form>
|
||||
{shortUrl && (
|
||||
<p className="mt-4 text-center text-gray-800">
|
||||
Short URL:{" "}
|
||||
<a
|
||||
href={shortUrl}
|
||||
className="text-blue-500 underline hover:text-blue-600"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{shortUrl}
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user