A service to shorten URLs. Only meant for personal use!
Code is open-sourced so it can serve as a reference.
- Client sends request to
/api/add-redirect?url={url}
- Server responds with
{ rerouteId: 'someId' }
- Server adds a new entry to the DB hosted on PlanetScale
- Client tries sending requests to
/{rerouteId}
until it gets a308
response, making sure that the redirect is now in place.
This project is using dracula-ui
, which is not an open source software.
If you have a GitHub account with access to dracula-ui
repo, you can
follow the installation steps for dracula-ui
which involves creating a custom
.npmrc
file.
- Install planetscale CLI
- Login to planetscale
pscale auth login
- Update the planetscale database schema
pscale database create reroute --region ap-southeast
pscale branch create reroute dev
(this is the dev DB)pscale branch create reroute main
(this is the prod DB)pscale shell reroute dev
(get a shell session to the dev branch)- Copy paste the command in
db/setup.sql
to create the table we need
- Copy paste the command in
yarn add prisma @prisma/client
npx prisma init
yarn dev
- Update
.env
with the value logged in console after runningyarn dev
:DATABASE_URL="mysql://root@127.0.0.1:3306/reroute"
npx prisma db pull
, allow prisma update the schema file according to the DB server)npx prisma generate
, allow prisma to generate theprisma-client
insidenode_modules
yarn db:seed
, seed the DB with some records
Add the official integration to the respective Vercel's project. It will take care of injecting the required environment variables.
-
If there are any changes to the DB schema, we should create a new deploy request
pscale deploy-request create reroute dev
Think of it like creating a PR to merge the
dev
branch to themain
branch, except it isdeploy-request
in PlanetScale's term. -
If there are conflicts, it should be resolved.
-
Once everything is fine, deploy the deploy-request by running
pscale deploy-request deploy reroute <deploy-request-number>