awy框架
awy2是一个使用NodeJS开发的Web框架,基于async和await关键字。
支持功能
- 中间件
- 路由
- 路由分组
- 中间件按照路由规则匹配执行
- 解析Body数据
- 解析上传的文件
- 启用守护进程模式
- 配置HTTPS
使用示例
const awy = require('awy2');
var ar = new awy();
ar.config.https_on = true;
ar.config.https_options.cert = '../rsa/localhost-cert.pem';
ar.config.https_options.key = '../rsa/localhost-privkey.pem';
ar.get('/', async rr => {
rr.res.Body = 'success';
});
ar.run('localhost', 8080);
curl 'http://localhost:8080/'
输出结果:
success
获取URL参数(QueryString参数)
const awy = require('awy2');
var ar = new awy();
ar.config.https_on = true;
ar.config.https_options.cert = '../rsa/localhost-cert.pem';
ar.config.https_options.key = '../rsa/localhost-privkey.pem';
ar.get('/test', async rr => {
var {name} = rr.req.Param;
console.log(name);
rr.res.Body = name;
});
ar.run('localhost', 8080);
curl 'http://localhost:8080/test?name=helo'
输出结果:
helo
获取POST提交的数据
const awy = require('awy');
var ar = new awy();
ar.config.https_on = true;
ar.config.https_options.cert = '../rsa/localhost-cert.pem';
ar.config.https_options.key = '../rsa/localhost-privkey.pem';
ar.post('/pt', async rr => {
var {username} = rr.req.BodyParam;
rr.res.Body = username;
});
ar.run('localhost', 8080);
curl 'http://localhost:8080/pt' -d 'username=albert'
返回结果:
albert
完整文档