1.1.0 • Published 8 years ago

plover-web-util v1.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

plover-web-util

NPM version build status Test coverage

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

Usage

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

Options

NameTypeDescription
keysString/Array设置cookie keys,详见 koa-keys
faviconStringfavicon图标的路径,详见 koa-favicon
rtimeBooleanResponse Header添加字段X-Response-Time显示响应时间,详见 koa-response-time
conditionalBoolean缓冲条件请求处理,详见 koa-conditional-get
etagBoolean支持ETag响应标签,详见 koa-etag
bodyParserBoolean解析request.body(默认开启),详见 koa-bodyparser
cookieSessionObject一个简单的基于cookiesession功能,详见 koa-session
csrfObjectCSRFtokens, 详见 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

NameValue
X-XSS-Protection1; mode=block
X-Content-Type-Optionsnosniff
X-Download-Optionsnoopen
X-Frame-OptionsSAMEORIGN