Last active
          August 29, 2015 14:15 
        
      - 
      
- 
        Save chrisveness/1e4eb603267ebbc32ca9 to your computer and use it in GitHub Desktop. 
Revisions
- 
        chrisveness revised this gist Feb 8, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,10 @@ "start": "nodemon --harmony -e js,json,html app.js" }, "dependencies": { "koa": "^0.17.0", "koa-flash": "^0.1.0", "koa-handlebars": "^0.5.0", "koa-router": "^3.8.0", "koa-session": "^3.1.0" } } 
- 
        chrisveness created this gist Feb 8, 2015 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ var koa = require('koa'); var session = require('koa-session'); var flash = require('koa-flash'); var router = require('koa-router'); var handlebars = require("koa-handlebars"); var app = koa(); app.keys = ['foo']; app.use(session({ domain: '.localhost' }, app)); // THIS FAILS //app.use(session(app)); // THIS WORKS app.use(flash()); app.use(handlebars({ extension: ['html'], viewsDir: './', partialsDir: './' })); app.use(router(app)); var handler = {}; handler.get = function*() { var context = {}; if (this.flash) context.flashmsg = this.flash.flashmsg; console.log('handler.get flash', this.flash); yield this.render('flash', context); }; handler.post = function*() { this.flash = { flashmsg: 'This is a flash' }; console.log('handler.post flash', this.flash); this.redirect(this.url); }; var routes = function(app) { app.get('/flash', handler.get); app.post('/flash', handler.post); }; routes(app); app.listen(process.env.PORT||3000); console.log(process.version+' listening on port '+(process.env.PORT||3000)+' ('+app.env+')'); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Flash test</title> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css"> </head> <body> <h1>Flash test</h1> {{#if flashmsg}}<p>Flash message: {{flashmsg}}</p>{{/if}} <form method="post"> <button type="submit">Submit</button> </form> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ { "main": "app.js", "scripts": { "start": "nodemon --harmony -e js,json,html app.js" }, "dependencies": { "koa": "", "koa-flash": "", "koa-handlebars": "", "koa-router": "", "koa-session": "" } }