// jshint node:true // jshint esversion:6 "use strict"; const http = require('http'), fs = require('fs'), path = require('path'), url = require('url'), phantom = require('phantom'), port = 8080; const decks = ["the_Unholy_Priest_update_2", "NZoths_Invasion_1.2", "Puffer_Fish_input_1.3"]; 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 'js': switch (pathParts[2]) { case 'playfield.js': case 'editor.js': case 'interact.js': sendFile(res, 'js/' + pathParts[2], 'application/javascript'); break; default: send404(res, uri); } break; case 'template': pathParts.splice(0, 2); // remove first two elements let item = pathParts.join("/"); console.log("template/" + item); switch (item) { case "card.json": case "deck.json": sendFile(res, "template/" + item, 'application/json'); break; case "environment/card.svg": case "hero/card.svg": case "hero/charBack.svg": case "hero/charFront.svg": case "villain/card.svg": case "villain/character.svg": case "villain/instructions.svg": sendFile(res, "template/" + item, 'image/svg+xml'); break; default: send404(res, uri); } break; case 'deck': if (pathParts.length < 3 || pathParts[2] === '') { sendIndex(res); break; } let deckName = decodeURI(pathParts[2]); if (!decks.includes(deckName)) { send404(res, uri); break; } switch (pathParts[3] || '') { case '': sendDeckIndex(res, deckName); break; case 'play': sendFile(res, 'html/playfield.html'); break; case 'editor': sendFile(res, 'html/editor.html'); break; case 'deck.png': sendFile(res, deckName + '.png', 'image/png'); break; case 'deck.json': sendFileJSON(res, deckName); break; case 'upload': handleUpload(res, req, deckName); 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 = `