// jshint node:true // jshint esversion:6 "use strict"; const http = require('http'), fs = require('fs'), url = require('url'), port = 8080; const server = http.createServer((req, res) => { const uri = url.parse(req.url); let pathParts = uri.pathname.split("/"); switch (pathParts[1]) { case '': case 'index.html': sendIndex(res); break; case 'style.css': sendFile(res, 'style.css', 'text/css'); break; case 'script.js': sendFile(res, 'script.js', 'application/javascript'); break; case 'interact.js': sendFile(res, 'interact.js', 'application/javascript'); break; case 'deck': if (pathParts.length === 3) { let deckName = pathParts[2]; sendDeckIndex(res, deckName); } else if (pathParts.length === 4) { let deckName = pathParts[2]; switch (pathParts[3]) { case 'play': sendPlayfield(res, deckName); break; case 'deck.png': sendFile(res, deckName + '.png', 'image/png'); break; case 'deck.json': sendFile(res, deckName + '.json', 'application/json'); break; default: send404(res, uri); } } break; default: send404(res, uri); } }); server.listen(process.env.PORT || port); console.log('listening on 8080'); function sendIndex(res) { const html = `
`; res.writeHead(200, {'contentType': 'text/html; charset=utf-8'}); res.end(html, 'utf-8'); } function sendDeckIndex(res, deckName) { const html = ` Play! `; res.writeHead(200, {'contentType': 'text/html; charset=utf-8'}); res.end(html, 'utf-8'); } function sendPlayfield(res, deckName) { const html = `