1.0.18 • Published 3 years ago

nv-cli-fastify-routes v1.0.18

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

nv-cli-fastify-routes

  • nv-cli-fastify-routes
  • cli tool, quickly generate template of routes for fastify using

install

  • npm install nv-cli-fastify-routes -g

usage

    Usage: nv_cli_froute [options]
    Options:
        -r, --routes        route names
        -h, --help          usage

  

example

first use nv_cli_back_nvproj to creat project

    # npm install nv-cli-back-nvproj -g
    # mkdir TEST
    # cd TEST

    # nv_cli_back_nvproj

    /*
    root@dev:/home/dev/TEST# nv_cli_back_nvproj
    ====http nginx example===

        server {
            listen 192.168.1.103:48001;
            location /TEST/http {
                proxy_pass http://unix:/home/dev/TEST/___http_usock___;
            }
        }


    root@dev:/home/dev/TEST# tree
    .
    ├── const.js
    ├── db
    ├── file
    ├── http
    ├── index.js
    ├── @lib
    │   └── cmmn
    │       └── index.js
    ├── redis
    ├── rtc
    └── ws
    */

then edit index.js

# vim index.js

//uncomment :
 
 	ENV.http  = await require("./http/index.js").init(ENV);

then goto the ./http to generate routes/dir/files

# cd http
# nv_cli_froute -r a/b/c/ a/e x y/@lib             //add some routes

/*
root@dev:/home/dev/TEST/http# tree
.
├── a
│   ├── b
│   │   ├── c
│   │   │   ├── err.js
│   │   │   └── index.js
│   │   ├── err.js
│   │   └── index.js
│   ├── e
│   │   ├── err.js
│   │   └── index.js
│   ├── err.js
│   └── index.js
├── err.js
├── index.js
├── x
│   ├── err.js
│   └── index.js
└── y
    ├── err.js
    ├── index.js
    └── @lib

*/

config nginx and test

nginx example

        server {
            listen 192.168.1.103:48001;
            location /TEST/http {
                proxy_pass http://unix:/home/dev/TEST/___http_usock___;
            }
        }

   

edit on route index ,such as 'a',

 # vim ./a/index.js
    ....
    function creat_cb(ENV) {
        let {user,redis,db,http,ws,rtc,file} = ENV;
        let _cb = async(request,reply) => {
             return({err:null,rslt:"hello"}) 
        }
        return(_cb)
    }

    ....

  #

goto ../ to start srv:

# cd ../

root@dev:/home/dev/TEST# node index.js
{"level":30,"time":1650540148686,"pid":3059102,"hostname":"dev","msg":"Server listening at /home/dev/TEST/___http_usock___"}
srv started:

   curl -H "Content-Type:application/json" -X POST -d '{"a":100}' http://192.168.1.103:48001/TEST/http/a
   
   {"err":null,"rslt":"hello"}

LICENSE

  • ISC
1.0.18

3 years ago

1.0.17

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago