The URL shortener of pia.sh Β·
- React.js
- Next.js
- MongoDB
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.
The web-app is hosted on Vercel. The database is hosted on MongoDB Atlas.
Any kind of contributions are welcome. Bump the version and create a PR.