Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

awy2

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

awy2

simple,small web framework

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

awy框架

awy2是一个基于Node.js的HTTP/2模块开发的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';

/*
一定要注意的是:
    回调函数要写成async rr的形式。
rr是打包了request和response的对象:
    {
        req,
        res
    }
    
*/

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

完整文档

Keywords

FAQs

Package last updated on 11 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc