Introduce HTML code as well as a JavaScript cookie implementation. default tip

Mon, 22 Dec 2014 23:44:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 22 Dec 2014 23:44:36 +0100
changeset 1
5f43030d87fe
parent 0
14388e456fdf

Introduce HTML code as well as a JavaScript cookie implementation.

bin/server file | annotate | diff | comparison | revisions
     1.1 --- a/bin/server	Mon Dec 22 23:02:08 2014 +0100
     1.2 +++ b/bin/server	Mon Dec 22 23:44:36 2014 +0100
     1.3 @@ -10,11 +10,32 @@
     1.4  }
     1.5  
     1.6  http.createServer(function (req, res) {
     1.7 -  res.writeHead(200, {'Content-Type': 'text/plain'});
     1.8 -  res.write('hello, I know nodejitsu.');
     1.9 +  var htmlcode = [
    1.10 +    '<!DOCTYPE html>',
    1.11 +    '<html>',
    1.12 +      '<head>',
    1.13 +        '<script type="text/javascript">',
    1.14 +          'var CookieName = "TestCookie";',
    1.15 +          'document.cookie = CookieName+"=yes;";',
    1.16 +          'if(document.cookie.indexOf(CookieName) == -1) {',
    1.17 +          '    alert("Cookies are required but you&#8217;re blocking them.");',
    1.18 +          '}',
    1.19 +        '</script>',
    1.20 +      '</head>',
    1.21 +      '<body>',
    1.22 +        '<p>Placeholder for forthcoming crossdomain cookie examination.</p>',
    1.23 +        '<p>Pending approval from Nodejitsu [1] administrators.</p>',
    1.24 +        '<p>[1] <a href="http://opensource.nodejitsu.com/">',
    1.25 +        '  http://opensource.nodejitsu.com/</a></p>',
    1.26 +      '</body>',
    1.27 +    '</html>'
    1.28 +  ].join('');
    1.29 +
    1.30 +  res.writeHead(200, {'Content-Length': Buffer.byteLength(htmlcode, 'utf8'),
    1.31 +                      'Content-Type': 'text/html;'
    1.32 +  });
    1.33 +  res.write(htmlcode);
    1.34    res.end();
    1.35  }).listen(port);
    1.36  
    1.37 -
    1.38 -
    1.39  console.log('The http server has started at: ' + url);

mercurial