demo.js 715 B

123456789101112131415161718192021
  1. var http = require('http'),
  2. session = require('./lib/core').session;
  3. // let's create a basic http server!
  4. http.createServer(function (request, response) {
  5. // before we process any part of the request, let's give it a session!
  6. session(request, response, function(request, response){
  7. // after the session middleware has executed, let's finish processing the request
  8. response.writeHead(200, {'Content-Type': 'text/plain'});
  9. response.write('hello, i know nodejitsu. \n' + 'the current session for this request looks like: \n' + JSON.stringify(request.session, 2, true));
  10. response.end();
  11. });
  12. }).listen(8080);
  13. /* server started */
  14. console.log('> hello world running on port 8080');