Skip to content

amio/now-go

Repository files navigation

now-go npm-version install-size

Create tinyurl/redirection service with ease.


Now go, let the legend come back to life!

Features

  • Lightweight tinyurl service (~50 sloc).
  • Three types of routes:
    • URL: redirect to an url
    • TEXT: echo a string
    • FUNCTION: accepts req argument, returns URL/TEXT routes
  • Deploy to now.sh with one command.

Quick Start

  • cli

    npm i -g now-go
    now-go -c path/to/config.json
  • programmatically

    const go = require('now-go')
    const config = require('./path/to/config.json') // routes config
    
    go(config)  // Start server on port 3000
  • create http handler

    const http = require('http')
    const { createHandler } = require('now-go')
    
    const config = require('./path/to/config.json')
    const handler = createHandler(config)
    
    http.createServer(handler).listen(3000)

Example configs

go-config.json

{
  // 302 redirection
  "/": "https://example.com",

  // echo text
  "/tag": "Now go, let the legend come back to life!",

  // "*" is a special route for unmatched path
  "*": "Yet another tinyurl service."
}

go-config.js

// redirect everything to new-example.com
module.exports = {
  "*": (req) => `https://new-example.com${req.url}`
}

Live Demo

License

MIT © Amio