Skip to content

maacpiash/piash-redirect-nextjs

Repository files navigation

The URL shortener of pia.sh Β· GitHub branch checks state

πŸ–₯ Technology Stack

  • React.js
  • Next.js
  • MongoDB

🧠 How it works

The web app redirects via the redirects option of the Next.js config file. Every request that looks like /{some-value} is redirected to /api/redirects/{some-value}, which is then handled by pages/api/[shortcut].js . It uses middleware/db.js to look up the URL assigned for the {some-value} string.

The database documents look like this:

{
    "_id": { "$oid": "5e0682401c9e4400007e440a" },
    "RealUrl": "https://github.com/maacpiash/static/raw/master/ahad-resume.pdf",
    "ShortKey": "resume"
}

The middleware finds the RealUrl of the document with the ShortKey value {some-value} and then redirects to that RealUrl.

However, the ednpoint that redirects /gh/{repo-name} to https://github.com/maacpiash/{repo-name} is hard-coded in the aforementioned config file. This is simpler and requires no database lookup.

🌏 Hosting

The web-app is hosted on Vercel. The database is hosted on MongoDB Atlas.

🀝🏽 Contributing

Any kind of contributions are welcome. Bump the version and create a PR.

About

🌏 🀏🏽 Next.js-based URL shortener of pia.sh

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published