plover-web-util

1.1.0 • Public • Published

plover-web-util

NPM version build status Test coverage

【插件】集成常用web中间件,提供通用web功能。

Usage

const app = plover({
  web: {
    keys: ['17e6b6bc6129097383dcad4fa1602233'],
    favicon: '',
    rtime: true
  }
});

Options

Name Type Description
keys String/Array 设置cookie keys,详见 koa-keys
favicon String favicon图标的路径,详见 koa-favicon
rtime Boolean Response Header添加字段X-Response-Time显示响应时间,详见 koa-response-time
conditional Boolean 缓冲条件请求处理,详见 koa-conditional-get
etag Boolean 支持ETag响应标签,详见 koa-etag
bodyParser Boolean 解析request.body(默认开启),详见 koa-bodyparser
cookieSession Object 一个简单的基于cookiesession功能,详见 koa-session
csrf Object CSRFtokens, 详见 koa-csrf

Others

query

query增强,若使用querystring传递多个相同值,最后一个值将覆盖前面的值。

假设访问地址为http://www.alibaba.com?name=james&name=tomy,在controller中获取的name值为tomy

// controller
console.log(this.query.name);  // tomy

params

params增强,params包括querystringrequest.body的值,如果存在相同值,后者将覆盖前者的值:

Query String Parameters

name: jame
age: 24

Form Data

name: tomy
address: hangzhou

controller中可以通过this.params很方便的获取querystringrequest.body的值:

// controller
console.log(this.params.name);  // tomy
console.log(this.params.age);  // 24
console.log(this.params.address);  // hangzhou

assertMethod

添加了assertMethod方法,方便验证Http Method:

//
this.ctx.assertMethod('GET');

output charset

可以通过querystring传递_output_charset参数指定响应输出编码格式。

security headers

设置安全http相关头,移除了X-Powered-By

Name Value
X-XSS-Protection 1; mode=block
X-Content-Type-Options nosniff
X-Download-Options noopen
X-Frame-Options SAMEORIGN

Readme

Keywords

none

Package Sidebar

Install

npm i plover-web-util

Weekly Downloads

2

Version

1.1.0

License

ISC

Last publish

Collaborators

  • bencode