Last active
October 1, 2015 19:38
-
-
Save egaumer/2046235 to your computer and use it in GitHub Desktop.
Basic session handling with evo server-side javascript controllers
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 characters
/* 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