Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
koa-flash fails when session domain opts set
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(handlebars({ extension: ['html'], viewsDir: './', partialsDir: './' }));
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);
}; = function*() {
this.flash = { flashmsg: 'This is a flash' };
console.log(' flash', this.flash);
var routes = function(app) {
app.get('/flash', handler.get);'/flash',;
console.log(process.version+' listening on port '+(process.env.PORT||3000)+' ('+app.env+')');
<!DOCTYPE html>
<meta charset="utf-8">
<title>Flash test</title>
<link rel="stylesheet" href="//">
<h1>Flash test</h1>
{{#if flashmsg}}<p>Flash message: {{flashmsg}}</p>{{/if}}
<form method="post">
<button type="submit">Submit</button>
"main": "app.js",
"scripts": {
"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"

This comment has been minimized.

Copy link
Owner Author

@chrisveness chrisveness commented Feb 20, 2015

Sorted! This was because cookies don’t work with ‘.localhost’ – see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment