bin/server

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
permissions
-rwxr-xr-x

Introduce HTML code as well as a JavaScript cookie implementation.

michael@0 1 #!/usr/bin/env node
michael@0 2
michael@0 3 var http = require('http'),
michael@0 4 port = 8080,
michael@0 5 url = 'http://localhost:' + port + '/';
michael@0 6 /* We can access nodejitsu enviroment variables from process.env */
michael@0 7 /* Note: the SUBDOMAIN variable will always be defined for a nodejitsu app */
michael@0 8 if(process.env.SUBDOMAIN){
michael@0 9 url = 'http://' + process.env.SUBDOMAIN + '.jit.su/';
michael@0 10 }
michael@0 11
michael@0 12 http.createServer(function (req, res) {
michael@1 13 var htmlcode = [
michael@1 14 '<!DOCTYPE html>',
michael@1 15 '<html>',
michael@1 16 '<head>',
michael@1 17 '<script type="text/javascript">',
michael@1 18 'var CookieName = "TestCookie";',
michael@1 19 'document.cookie = CookieName+"=yes;";',
michael@1 20 'if(document.cookie.indexOf(CookieName) == -1) {',
michael@1 21 ' alert("Cookies are required but you&#8217;re blocking them.");',
michael@1 22 '}',
michael@1 23 '</script>',
michael@1 24 '</head>',
michael@1 25 '<body>',
michael@1 26 '<p>Placeholder for forthcoming crossdomain cookie examination.</p>',
michael@1 27 '<p>Pending approval from Nodejitsu [1] administrators.</p>',
michael@1 28 '<p>[1] <a href="http://opensource.nodejitsu.com/">',
michael@1 29 ' http://opensource.nodejitsu.com/</a></p>',
michael@1 30 '</body>',
michael@1 31 '</html>'
michael@1 32 ].join('');
michael@1 33
michael@1 34 res.writeHead(200, {'Content-Length': Buffer.byteLength(htmlcode, 'utf8'),
michael@1 35 'Content-Type': 'text/html;'
michael@1 36 });
michael@1 37 res.write(htmlcode);
michael@0 38 res.end();
michael@0 39 }).listen(port);
michael@0 40
michael@0 41 console.log('The http server has started at: ' + url);

mercurial