_/_/_/_/ _/ _/ _/
_/ _/ _/ _/
_/_/_/ _/ _/
_/ _/ _/
_/ _/_/_/_/ _/
FLY
is f
unctionally
: A library for develop backend easy.
- Isolation: one file is one function
- Modularization: one directory is one service
- Configurability: config anything hierarchically
Installation
Require node >= 8
$ yarn global add fly
$ npm install -g fly
Example
Write function
proxy.js
module.exports = {
async main (event, context) {
return {url : event.query.url}
},
configHttp: {
method: 'GET',
path: '/proxy'
}
}
Run
$ fly http -r ↙
┌────────┬────────────────┬────────┬────────┐
│ Method │ Path │ Domain │ Fn │
│ GET │ /api │ │ index │
│ GET │ /api/userLogin │ │ login │
│ POST │ /upload │ │ upload │
│ GET │ / │ │ home │
│ GET │ /static/:path+ │ │ static │
└────────┴────────────────┴────────┴────────┘
SERVER READY
NAME: HTTP
ADDRESS: http://127.0.0.1:5000
PID: 20815
WORK DIR: /Users/YourName/Code/fly-example
HOT RELOAD: true
Defintions
Function Defintion
{
extends: String,
imports: Object {String: String}
config: Object {String: Any},
retry: Number || Boolean,
main: Function (event, ctx),
validate: Function (event, ctx),
before: Function (event, ctx),
after: Function (event, ctx),
catch: Function (event, ctx),
config<Event>: Object || Boolean || Function,
before<Event>: Function (event, ctx),
after<Event>: Function (event, ctx),
validate<Event>: Function (event, ctx),
catch<Event>: Function (event, ctx),
}
Context Defintion
eventId: String
eventType: String
originalEvent: Event
parentEvent: Event
call: Function
list: Function
get: Function
error: Function
<fn>: Function
trace: Object
config: Object
Command Usage
Usage:
fly <command> [--options]
System Commands:
api [command] API service
[command] start | stop | reload | restart | status | log
--port,-p number Bind port
--instance,-i number The instance number
--all,-a All applications
--bind,-b string
call <fn> Call function
<fn> Function name
--type string Set event type
--data,-d string Set event data
--timeout, -t Set timeout
show <fn> Show function info
<fn> Function name
help Show help
--system,-s Show system commands
http [command] HTTP service
[command] start | stop | reload | restart | status | log
--port,-p number Bind port
--instance,-i number The instance number
--all,-a All applications
--bind,-b string
--hotreload,-r Run with hot reload mode
install Install deps
--list,-l List packages to install
list List functions
--type string List with type
--all List all commands
new [dir] Create new service dir
[dir] Dir name
--force Force create when dir exists
serve [command] Serve service
[command] start | stop | reload | restart | status | log
--port,-p number Bind port
--instance,-i number The instance number
--all,-a All applications
--bind,-b string
Global options:
--id,-i string Set event id
--verbose,-V Show verbose
Events
Event can be anything, but must can be JSONify
HTTP
Http Event
method: String
path: String
origin: String
host: String
domain: String
url: String
protocol: String
port: Number
ip: String
headers: Object
body: Object
files: Object
query: Object
search: String
cookies: Object
Http Config
method: String
path: String
domain: String | Array
cache: Boolean | Number
cors: Boolean | String
origin: String
headers: String
methods: String
upload:
allowTypes: Array
maxSize: Number
Command
Command Event
args: Object
params: Object
Command Config
_: String
args: Object
alias: Object
descriptions: Object
_: String
<param>: String
<args>: String
Command Example
module.exports = {
main (event, ctx) {
const command = event.params.command
const showFull = event.args.full
},
configCommand: {
_: 'help <command>',
args: {
'--full': Boolean
},
alias: {
'--full': '-f'
},
descriptions: {
_: 'Show help for commands',
'<help>': 'Command name'
'--full': 'Show full descriptions'
}
}
}
Cron
Cron Event
time: timestamp
Cron Config
time: '* * * * *'
timeout: 60
Cron Example
module.exports = {
main (event, ctx) {
},
configCron: {
time: '*/30 * * * *'
}
}
fly.yml
Optional. You can place fly.yml
in directory to overwrite funciton's config
fly.yml
files:
- "**/*.fly.js"
events:
http:
domain:
- api.com
- localhost
config:
db:
host: localhost
module@:
db: 'test:3333'
url@:
url: hello
API
You can use in Nodejs and call fly function directly
Usage
const Fly = require('node-fly')
const fly = new Fly('/dir')
await fly.call('test', {host: 'api.com'})
LICENSE
Copyright (c) 2019 hfcorriez hfcorriez@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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 NONINFRINGEMENT. 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.