Skip to content

Instantly share code, notes, and snippets.

@egaumer
Last active October 1, 2015 19:38
Show Gist options
  • Save egaumer/2046235 to your computer and use it in GitHub Desktop.
Save egaumer/2046235 to your computer and use it in GitHub Desktop.
Basic session handling with evo server-side javascript controllers
/* the controller */
function session() {
function doGet(session) {
return { body: ["This method is public"] };
}
function doPut(session) {
if (!session) {
/* user not logged in - send redirect */
return {
status: 302,
headers: { "Location": "/evo/auth/login" }
};
}
return { body: [session.id, ":", session.role] };
}
return {
/* controller action */
test: function(request) {
return {
GET: doGet,
PUT: doPut
}[request.method](request.session);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment