DEV Community

Build your own URL shortener in 15 minutes

Sebastiaan Deckers on January 20, 2019

The Commons Host CDN platform recently introduced support for custom HTTP response headers and redirect rules. Let's use these features to build ou...
Collapse
 
craigz profile image
craigz

this is great and it 'works' inso as much as locally issuing the command 'npx short [URL]' generates a lovely shortened link using my custom domain, which it does write into the commonshost.json file. however, that link is unusable as attempts to connect to the url fail whichever browser i use. the cname for my custom domain is configured and working from the command line (it resolves to commons.host). deploying the site reports success although it also throws the following error: "(node:12208) [DEP0135] DeprecationWarning: ReadStream.prototype.open() is deprecated"

so as it stands, i have a nice framework and an npx command, but really in terms of doing anything with this, am unable to do so. i'm trying to wrap my head around the docs at commonshost, but lining up their default install with what's going on here with the redirects is not making a load of sense.

i'd be open to any suggestions as i'd love to move forward with this as a shortener and not be required to mess with php as most of the self hosted options seem to be using. i'm also not interested in using bit.ly as a backend.

thanks for an interesting start at least!

Collapse
 
sebdeckers profile image
Sebastiaan Deckers

Hey, could you tell me the domain name you're using? Might be a DNS or TLS certificate issue.

Finally got around to looking into the short tool. Refactored its code and added unit/regression tests. I also fixed that deprecation warning in the deploy tool. Just verified that it works on my machineℒ️. πŸ˜…

Will take a look at editing the Commons Host docs. Right now it's partly my own docs to configure the CDN platform, mixed in with docs for users of the various offered services (CDN, static hosting, DNS over HTTPS, even a Gopher client and proxy 😝).

Collapse
 
craigz profile image
craigz

hey, thanks for getting back to me!

after reading your comment i reviewed my notes and app from back then and gave it all another try and this time around things seem to work just fine. additionally, i've updated short to version 5.1.0 and sure enough, no more deprecation warning. most excellent. so i've got a working cli shortener.

now that it's working of course i want to take it further, i saw in another comment the link to the api which is exciting. i'm not entirely certain how to work with it, but i've started by installing @commonshost/short as a dev-dependency in a new project. i'm going to hack on this some over the weekend.

Collapse
 
sebdeckers profile image
Sebastiaan Deckers

Thanks for the bug report. πŸ™‡πŸΌβ€β™‚οΈ I'll take a look to see what needs to be updated in this blog post.

Collapse
 
philsmy profile image
Phil Smy

Nice...but how to do this programmatically? having a manual link shortener (that you call from the command line!) isn't THAT useful!

Collapse
 
sebdeckers profile image
Sebastiaan Deckers

Thanks for the useful suggestion. An API for short is now available: gitlab.com/commonshost/short#api

This tool started as a simple demo showcase but quite a few people seem to be looking for this type of solution. I'm happy to make it more useful if you provide more feedback.

Collapse
 
greenwichmytime profile image
GreenwichMyTime

Hi

Any examples of anybody deploying this for their own url shortener?

Collapse
 
sebdeckers profile image
Sebastiaan Deckers

I've received emails with tech questions from a few people. No idea how many are really using it, or how much traffic they see. I remember @donavon tried it briefly, but not sure if that was continued.

Collapse
 
casacode profile image
Brian Liotti

InternalServerError: ENOSPC: no space left on device, write

bummer

Collapse
 
sebdeckers profile image
Sebastiaan Deckers

Had some issues with flaky, large deployments causing the scratch space on the Commons Host core API server to fill up and never get cleared until a reboot. I fixed a few bugs recently that should prevent those problems from recurring. (See: gitlab.com/commonshost/support/iss...)

Collapse
 
mardeg profile image
Mardeg

The problem is recurring πŸ˜’ and shows up only at the end of uploading a (45MB) site.

InternalServerError: ENOSPC: no space left on device, write

at module.exports.parseError (/usr/lib/node_modules/@commonshost/cli/src/helpers/parseError.js:17:11)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /usr/lib/node_modules/@commonshost/cli/src/commands/deploy.js:460:28
Enter fullscreen mode Exit fullscreen mode