diff --git a/css/style.js b/css/style.js new file mode 100644 index 0000000..1359e64 --- /dev/null +++ b/css/style.js @@ -0,0 +1,82 @@ +module.exports = () => { + return ` +body { + font-family: sans-serif; +} + +#grid { + display: flex; + flex-wrap: wrap; + justify-content: center; +} + +.item { + margin: 20px; + flex: 1; + border: 1px solid #999; +} + +.name { + padding: 10px 20px; + font-size: 80px; + text-align: center; +} + +.cash { + padding: 20px 40px; + font-size: 100px; + text-align: center; +} + +.cash::before { + content: "$"; +} + +#topbar { + background-color: rgb(30, 62, 46); + color: #fff; + padding: 10px 20px; +} + +#topbar h1 { + display: inline; + margin-right: 2em; +} + +.GT { + color: black; + background-color: orange; +} + +.PRR { + color: white; + background-color: red; +} + +.B_O { + color: white; + background-color: blue; +} + +.ERIE { + color: black; + background-color: yellow; +} + +.IC { + color: white; + background-color: darkgreen; +} + +.C_O { + color: white; + background-color: lightblue; +} + +.NYC { + color: white; + background-color: black; +} + + `.trim() +} diff --git a/index.js b/index.js index c397491..52ff83c 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const Koa = require("koa") const bodyParser = require("koa-bodyparser") const Router = require("koa-router") +const port = process.env.PORT || 3000 + const app = new Koa() app.use(bodyParser()) @@ -32,6 +34,6 @@ require("./routes/18sh")({ router }) app.use(router.routes()) app.use(router.allowedMethods()) -if (!module.parent) app.listen(3018) +if (!module.parent) app.listen(port) module.exports = app diff --git a/modules/gameFormat.js b/modules/gameFormat.js index 96c589e..341efd7 100644 --- a/modules/gameFormat.js +++ b/modules/gameFormat.js @@ -1,55 +1,36 @@ "use strict" module.exports = (title, data) => { - const css = ` - - `.trim() + const css = require("../css/style") const cashHoldings = Object.keys(data).map(key => { const cash = data[key] - return `
${key}
${cash}
` + const className = key.replace(/[^\w\d]/, "_") + return `
${key}
${cash}
` }) const cashHTML = cashHoldings.join("") + const today = new Date() + const time = + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + const topBarContent = ` - Pro tip: Zoom in in the browser until the boxes fill up screen nicely. + Pro tip: Zoom in in the browser until the boxes fill up screen nicely. Last refresh: ${time} `.trim() - return `18SH: ${title}${css}

${title}

${topBarContent}
${cashHTML}
` + return ` + + + 18SH: ${title} + + + + +
+

${title}

${topBarContent} +
+
${cashHTML}
+ + + `.trim() } diff --git a/package.json b/package.json index f45dcef..c46ca05 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ "games", "boardgames" ], + "engines": { + "node": "12.x" + }, "author": "Mikko Saari", "license": "MIT", "dependencies": { diff --git a/rest/post_game.rest b/rest/post_game.rest index 4e3b058..ed8e082 100644 --- a/rest/post_game.rest +++ b/rest/post_game.rest @@ -2,12 +2,6 @@ POST http://localhost:3018/18sh/ Content-Type: application/json { - "name": "rusty-incident", - "data": { - "MIKKO": "300", - "NOOA": "245", - "GT": "124", - "NBR": "1245", - "bank": "124" - } + "name": "eneloop", + "data": { "bank": 3400, "MIKKO": -440, "NOOA": 1040, "GT": 0 } } \ No newline at end of file diff --git a/routes/18sh.js b/routes/18sh.js index f555709..52ef5cd 100644 --- a/routes/18sh.js +++ b/routes/18sh.js @@ -23,7 +23,7 @@ module.exports = ({ router }) => { const conf = new Configstore(body.name) conf.set("data", body.data) - ctx.status = 201 + ctx.status = 200 ctx.body = "Ok!" }) }