2021-02-06

Deploying dotco

I need a link shortener, Somesh's dotco is a good option, since it runs on Vercel (free) and uses Airtable as a database (free).

A nice upside to Airtable is the fact that you get a nice interface to edit your data. Unfortunately, Somesh's repo doesn't have any deployment instructions. So I guess I'll have to figure that out myself.

I'll start by forking the repo and pulling the fork down onto my machine since I plan to send a pull request with the documentation.

npm i
# Run the app
node index

The GitHub redirect is setup to redirect to Somesh's Github by default. I created an env var for the GitHub username and set it up in the route.

Then I setup the Airtable doc. This is what it looks like

airtable

Looks good! Now I just need to get this up on Vercel.

Deployment was direct, added the environment variables and domain and everything worked fine.

2021-05-07 06:49 IST

Adding a script to create shortlinks

I want a script I can run from my shell to create shortlinks, I want it to look something like this.

shortlink "https://very-long-irrelevent-url.com" shortlink

All I really have to do is take the URL and slug from process.argv and add them to Airtable. Easy enough!

let [target, slug] = process.argv.slice(2)
slug = slug || crypto.randomBytes(5).toString('hex')

airtable
  .create({ target, slug })
  .then(() => {
    console.log(`Created ${process.env.MAIN_DOMAIN}/${slug}`)
  })
  .catch((e) => console.error(e))

Now I just need to create an alias.

alias short ~/src/dotco/bin/shortlink
funcsave short