• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

rickharrison/koa-flash: Flash messages for your koa application.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

rickharrison/koa-flash

开源软件地址:

https://github.com/rickharrison/koa-flash

开源编程语言:

JavaScript 97.4%

开源软件介绍:

#koa-flash

Flash messages for your koa application.

Build Status

Installation

$ npm install koa-flash

koa-flash also depends on koa-session. You must add koa-session as a middleware prior to adding koa-flash as seen in the example:

Example

var koa = require('koa')
  , session = require('koa-session')
  , flash = require('koa-flash');

var app = koa();

app.keys = ['foo'];
app.use(session());
app.use(flash());

app.use(function *() {
  if (this.method === 'POST') {
    this.flash = { error: 'This is a flash error message.' };
  } else if (this.method === 'GET') {
    this.body = this.flash.error || 'No flash data.';
  }
});

app.listen(3000);

Semantics

Flash data when set will be saved to the user's session for exactly one more request. You can save any javascript object into this.flash (Object, Number, String, etc.). A common use case is to save an error message from a POST request when redirecting to a GET request to display the form again.

Options

Flash data is saved into this.session['koa-flash'] by default. You can change this by passing in a key option.

app.use(flash({ key: 'foo' }));

Also, you can set defaultValue instead of {}.

app.use(flash({ defaultValue: 'bar' }));

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
sunyongjian/koa2-proxy-middleware发布时间:2022-07-09
下一篇:
rudijs/koa-json-logger: KoaJS HTTP Request/Response/Error JSON format logger发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap