forked from fastify/fastify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.tmpl
More file actions
74 lines (61 loc) · 2.32 KB
/
README.tmpl
File metadata and controls
74 lines (61 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# fastify-cli
[](http://standardjs.com/) [](https://travis-ci.org/fastify/fastify-cli)
Command line tools for [fastify](https://github.com/mcollina/fastify).
Write and run a route with one single command!
## Install
```bash
npm install fastify-cli --global
```
## Usage
Example:
```js
// plugin.js
module.exports = function (fastify, options, next) {
fastify.get('/', function (req, reply) {
reply.send({ hello: 'world' })
})
next()
}
```
You can easily run it with:
```bash
$ fastify plugin.js
```
If fastify has been installed local to plugin.js that copy will be used instead of the global copy included with fastify-cli.
You can use `async` functions too, and make your plugin more concise:
```js
// async-await-plugin.js
module.exports = async function (fastify, options) {
fastify.get('/', async function (req, reply) {
return { hello: 'world' }
})
}
```
CLI options:
```bash
${help.txt}
```
If you want to use custom options, just export an options object with your route and run the cli command with the `--options` flag.
```js
// plugin.js
module.exports = function (fastify, options, next) {
fastify.get('/', function (req, reply) {
reply.send({ hello: 'world' })
})
next()
}
module.exports.options = {
https: {
key: 'key',
cert: 'cert'
}
}
```
## Contributing
If you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.
The code follows the Standard code style.
[](https://github.com/feross/standard)
## License
**[MIT](https://github.com/delvedor/fastify-cli/blob/master/LICENSE)**
*The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.*
Copyright © 2016-2017 Tomas Della Vedova