Chad Krause

A small blog about my projects

Chad's URL Shortener Part 3 - Meat & Bones

4/2/2018 1:00PM

What have I done so far, code wise?

  • Designed database
  • Wrote migrations

I'm going to avoid making this a How-To and more of just sprawl of my thoughts

4/2/2018 4:00PM

I have done some more work:

  • Created models for my database
  • Created and connected database to project
  • Made RedirectController
  • New Log table for short codes that aren't valid

So far, if you go to a vaild short code, it will return some JSON that includes the model for the URL and the IPAddress:

        "id": 1,
        "url": "",
        "short_code": "chad",
        "ipaddressid": 1,
        "created_at": "2019-04-01 08:56:40",
        "updated_at": "2019-04-01 08:56:40"
        "id": 2,
        "address": "",
        "created_at": "2019-04-02 17:52:11",
        "updated_at": "2019-04-02 17:52:11"

That's actually all you need to properly redirect. It's easy to redirect from there. I still have to have the ability to make a shortened URL. Which seems harder. Again, now there is the problem of how to make short codes. I am choosing the "Random chance" method, with retries if it doesn't find another short code that works. Also, I have to prevent the creation of URLs that are already shortened by my site.

But first I have to make some decisions... Do I use a javascript framework like Angular (That I know very well), or do I just use the MVC framework by laravel?

My gut instinct says go with Angular, but then there is a problem with routings. But also, I know how to do very cool things like graphs for user information.

Sidetrack Alert

I think I need more information than just IP address. I am also going to track user agent. User agent is the information sent along with any request that gives information about the device. That's how sites know what version of software to download to your device (Mac vs Windows vs Linux). It's also one of the ways they know if your device is a phone or tablet or desktop. Here is what the user agent looks like:

You'll a few things:

  • Mozilla/5.0
  • (Macintosh; Intel Mac OS X 10_14_3)
  • AppleWebKit/537.36 (KHTML, like Gecko)
  • Chrome/72.0.3626.121
  • Safari/537.36

Some of this is common sense, like the fact I'm running a Macintosh with an Intel running OSX 10.14.3. The browser renders using Apple WebKit ver. 537.36. It also lists Mozilla/5.0, Chrome/72.0.3626.121, and Safari/537.36. The Mozilla/5.0 just means it's "Mozilla Compatible". The Chrome/72.0.3626.121 means that I'm running Chrome version 72. But what does the Safari/537.36 mean? It just means that it is also Safari compatible. Some servers used to block certain browsers that wouldn't be supported. Not sure why but now it's some old stuff that is still sent along with requests (if you're using http/1.1)

Done for now, check next post.

All comments