aok.js

2.4.1 • Public • Published

aok.js

reverse the koa , ROP resource oriented program

phil(哲学)

phil

about version

v2.0.0

  1. add .aokignore just like .gitignore
  2. 默认忽略扫描node_modules/的文件
  3. ext 扩展功能,详见 ext 参考下面的csv.aok
  4. 支持csv扩展 csv.aok

just step by step to understand aok

npm i -g aok.js
 
mkdir temp
cd temp
 
cat << EOF > data.json
{
    "hello":"good good day"
}
EOF
 
aok . 
 
# try  visit by http 
#GET : http://localhost:11540/data?node=hello 
#POST : http://localhost:11540/data 
#PUT : http://localhost:11540/data?node= 
#DELETE : http://localhost:11540/data?node= 

what is aok

参数说明:
  1. 暴露出去的资源方法,同时支持同步及异步方法

    {
        "@get" : (params , ctx , options) =>{
            // return {}
            // return []
            return Promise.resolve(1)
        },
        "@post" : async (params , ctx , options) =>{
            // return {}
            // return []
            return Promise.resolve(1)
        }
    }
  2. 也支持其他形式

    {
        "@delete" :  'test delete success',
        "@put" : {
            hello : 'good good day'
        }
    }
  3. 方法参数说明

    params : get时 ctx.query 其他methods 时 取 ctx.request.body

    ctx : 请求上下文

    options : 程序启动的options,应用直接获取做一些特殊处理

  4. 文件上传支持

    采用koa-body方式上传文件,ctx.request.files直接获取

use

cli

npm i -g aok.js
 
aok -h 
 
aok [yourDir] -s [yourStaticDir] -p [yourport]
 

amazing using

npm i -g lisa.dl
 
aok https://github.com/apporoad/aok.js/blob/master/example/example.zip?raw=true --type zip
 
# more in aok -h 
 
aok https://github.com/apporoad/pnote.git --type git -r api -s static -w pnote -d
 

code

npm i --save aok.js
const aok = require('aok.js')
 
aok.mount('yourDirPath', 'yourStaticDirPath',{ port:11540})
 

how to debug

debug use debug

# LINUX 
DEBUG=* aok xxx xxx
 
#windows powershell 
$env:DEBUG = "*,-not_this"

how to deploy

npm i -g pm2
npm i -g aok.js
 
pm2 start --name yourApp aok -- . -p 11540
 

ps

we use '_any_' as '*' with your fileName

you can : 
_any_.js => /*
abc/_any_.js => /abc/*

// .json support  json node operations

you can :

GET http://localhost:11540/?node=abc.hello
PUT http://localhost:11540/?node=abc.hello
DELETE http://localhost:11540/?node=abc.hello

just try it

docker

jump

how to debug

推荐做法是直接采用本地引用,直接调用方式
一些情况必须启动aok,vscode 采用如下配置方式:

{
    "program": "/usr/local/bin/aok",
    "args": ["${workspaceFolder}/api" , "-p" ,"10000"]
}
 

examples

  1. pnote
  2. apinfo
  3. dmodule
  4. danmu.js
  5. adding

Package Sidebar

Install

npm i aok.js

Weekly Downloads

1

Version

2.4.1

License

MIT

Unpacked Size

36.4 kB

Total Files

8

Last publish

Collaborators

  • apporoad