GithubHelp home page GithubHelp logo

fejalish / koa-flash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rickharrison/koa-flash

0.0 5.0 0.0 9 KB

Flash messages for your koa application.

License: MIT License

Makefile 2.60% JavaScript 97.40%

koa-flash's Introduction

#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

koa-flash's People

Contributors

fejalish avatar rickharrison avatar nswbmw avatar bdentino avatar

Watchers

Andrew Fenn avatar  avatar Drew Kam avatar James Cloos avatar Andreas Holmer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.