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