1 | # now-go [![npm-version][npm-badge]][npm-link]
|
2 |
|
3 | A tinyurl service.
|
4 |
|
5 | <p align="center">
|
6 | <img src="https://amio.github.io/now-go/hero.jpg" /><br/>
|
7 | <i>Now go, let the legend come back to life!</i>
|
8 | </p>
|
9 |
|
10 | ## Features
|
11 |
|
12 | - Lightweight tinyurl service (in 100 lines).
|
13 | - Three types of routes:
|
14 | - URL: redirect to an url
|
15 | - TEXT: echo a string
|
16 | - FUNCTION: return a URL/TEXT by `req` argument
|
17 | - Deploy to now.sh with one command.
|
18 |
|
19 | ## Quick Start
|
20 |
|
21 | - cli
|
22 | ```
|
23 | npm i -g now-go
|
24 | now-go -c path/to/config.json
|
25 | ```
|
26 |
|
27 | - programmatically
|
28 | ```javascript
|
29 | const go = require('now-go')
|
30 | const config = require('./path/to/config.json') // routes config
|
31 |
|
32 | go(config) // Start server on port 3000
|
33 | ```
|
34 |
|
35 | ## Example config
|
36 |
|
37 | content of `config.json`:
|
38 |
|
39 | ```javascript
|
40 | {
|
41 | // 302 redirection
|
42 | "/": "https://example.com",
|
43 |
|
44 | // echo text
|
45 | "/tag": "Now go, let the legend come back to life!",
|
46 |
|
47 | // "*" is a special route for unmatched path
|
48 | "*": "Yet another tinyurl service."
|
49 | }
|
50 | ```
|
51 |
|
52 | or you can use function for more advanced usage, like [`example.config.js`](example.config.js) (*The config for http://go.now.sh.*)
|
53 |
|
54 | ```javascript
|
55 | // example.config.js
|
56 | module.exports = {
|
57 | // stright routes
|
58 | "/": "https://example.com",
|
59 | "/hi": "Hello there!",
|
60 |
|
61 | // functional route
|
62 | "*": (req) => `This ${req.url} leads to nowhere.`
|
63 | }
|
64 | ```
|
65 |
|
66 | ## License
|
67 |
|
68 | [MIT][mit-link] © [Amio][author]
|
69 |
|
70 | [npm-badge]:https://img.shields.io/npm/v/now-go.svg?style=flat-square
|
71 | [npm-link]: http://www.npmjs.com/package/now-go
|
72 | [mit-link]: http://opensource.org/licenses/MIT
|
73 | [author]: http://github.com/amio
|