Skip to content

Conversation

@Hutotpn
Copy link
Owner

@Hutotpn Hutotpn commented May 26, 2025

This pull request introduces functionality for creating and redirecting shortened URLs using the Appwrite backend. It also refactors the api/redirect.js file to improve code reuse by initializing the Appwrite client at the top of the file instead of within the handler function.

New Feature: URL Shortening

  • Added a new API endpoint in api/create.js to handle the creation of shortened URLs. This endpoint initializes the Appwrite client, creates a document in the database with the provided shortCode and longURL, and returns the shortened URL upon success.

Code Refactoring: Appwrite Client Initialization

  • Moved the initialization of the Appwrite client and database in api/redirect.js to the top of the file, outside the handler function, to improve code reuse and reduce redundancy. [1] [2]

@Hutotpn Hutotpn requested a review from Copilot May 26, 2025 14:25
@Hutotpn Hutotpn self-assigned this May 26, 2025
@Hutotpn Hutotpn added the enhancement New feature or request label May 26, 2025
@Hutotpn Hutotpn linked an issue May 26, 2025 that may be closed by this pull request
@vercel
Copy link

vercel bot commented May 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
url-shortener ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 26, 2025 2:41pm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new API endpoint for creating shortened URLs and refactors the Appwrite client initialization in the redirect endpoint for improved code reuse.

  • Added api/create.js for handling URL shortening with document creation in the Appwrite database.
  • Moved client and database initialization in api/redirect.js to the top of the file to eliminate redundancy.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
api/redirect.js Refactored to initialize the Appwrite client and database at the top.
api/create.js Added a new endpoint to create a short URL, with creation logic in the Appwrite database.


console.log("Create URL: ", shortCode, "\n", "Long URL: ", longURL);

if (!shortCode && !longURL) {
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition uses '&&' instead of '||'. This may allow one of the required parameters to be missing. Update the condition to 'if (!shortCode || !longURL)' to ensure both parameters are provided.

Suggested change
if (!shortCode && !longURL) {
if (!shortCode || !longURL) {

Copilot uses AI. Check for mistakes.
@Hutotpn Hutotpn merged commit 78b83a4 into master May 26, 2025
2 checks passed
@Hutotpn Hutotpn deleted the 7-create-short-url-api branch May 26, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create short URL API

2 participants