url-shortener

Spawn up a simple webserver to act as a URL shortener

url-shortener

Spawn up a simple webserver to act as a URL shortener

$ cp config.json{.dist,}; cp urls.json{.dist,}
$ ./server.js
Server listening on localhost:8090
{ paste: 'http://www.pastebin.com',
  github: 'https://github.com' }
Request received /
Request received /paste
$ curl -s localhost:8090 | json
{
  "paste": "http://www.pastebin.com",
  "github": "https://github.com"
}
$ curl -I localhost:8090/paste
HTTP/1.1 301 Moved Permanently
Location: http://www.pastebin.com
Connection: keep-alive

There are 2 config files. The first is config.json, and in there you define the host and port the server should listen on, and the URLs json file to use. You can also include a uid/gid the process should run as after binding to the port. The second is urls.json, and this is key-value file of path to URL.

{
  "host": "localhost",
  "port": 8090,
  "urls": "./urls.json",
  "gid": null,
  "uid": null
}
{
  "paste": "http://www.pastebin.com",
  "github": "https://github.com"
}

MIT Licensed