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

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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';

/*
一定要注意的是:
    回调函数要写成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 => {
    //获取name,如果不存在则默认返回空字符串。
    //如果第二个参数不填写,则name不存在会返回null。
    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 26 Jul 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