This is a URL shortener project built with Next.js. It allows users to shorten long URLs and provides a short link that redirects to the original URL.
- Shorten long URLs
- Redirect to the original URL using the short link
- Display a message if the short link is not found
- Node.js (v14 or later)
- npm or yarn
-
Clone the repository:
git clone https://github.com/your-username/shorturl.git cd shorturl
-
Install dependencies:
npm install # or yarn install
-
Create a
.env
file in the root directory and add your PostgreSQL connection string:POSTGRES_URL=your_pooled_connection_string
Start the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
To create an optimized production build:
npm run build
# or
yarn build
To start the production server:
npm start
# or
yarn start
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out the Next.js deployment documentation for more details.
-
src/app/[key]/page.tsx
: Handles the redirection logic based on the short link key.startLine: 1 endLine: 21
-
src/app/api/route.ts
: API route to create a short link.startLine: 1 endLine: 52
-
src/app/layout.tsx
: Root layout component.startLine: 1 endLine: 20
-
src/app/page.tsx
: Home page component.startLine: 1 endLine: 27
-
src/components/ShortenForm.tsx
: Form component to input the URL to be shortened.startLine: 1 endLine: 59
-
src/lib/db.ts
: Database connection logic.startLine: 1 endLine: 22
-
src/lib/seed.ts
: Database seeding logic.startLine: 1 endLine: 12
-
src/models/apiResponse.model.ts
: TypeScript interface for API response.startLine: 1 endLine: 4
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
This project is licensed under the MIT License.
This README provides a clear overview of the project, including installation instructions, project structure, and links to relevant resources.