Skip to content

Commit

Permalink
Fixed for Heroku.
Browse files Browse the repository at this point in the history
  • Loading branch information
msaari committed Jul 8, 2019
1 parent a24aea7 commit f2efd2c
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 52 deletions.
82 changes: 82 additions & 0 deletions css/style.js
Original file line number Diff line number Diff line change
@@ -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()
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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
65 changes: 23 additions & 42 deletions modules/gameFormat.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,36 @@
"use strict"

module.exports = (title, data) => {
const css = `
<style type="text/css">
#grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.item {
padding: 40px;
flex: 1;
}
.name {
font-size: 80px;
text-align: center;
}
.cash {
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;
}
</style>
`.trim()
const css = require("../css/style")

const cashHoldings = Object.keys(data).map(key => {
const cash = data[key]
return `<div class="item"><div class="name">${key}</div><div class="cash">${cash}</div></div>`
const className = key.replace(/[^\w\d]/, "_")
return `<div class="item"><div class="name ${className}">${key}</div><div class="cash">${cash}</div></div>`
})
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 `<html><head><title>18SH: ${title}</title>${css}</head><body><div id="topbar"><h1>${title}</h1> <span>${topBarContent}</span></div><div id="grid">${cashHTML}</div></body></html>`
return `
<html>
<head>
<title>18SH: ${title}</title>
<style type="text/css">${css()}</style>
<meta http-equiv="refresh" content="30" />
</head>
<body>
<div id="topbar">
<h1>${title}</h1> <span>${topBarContent}</span>
</div>
<div id="grid">${cashHTML}</div>
</body>
</html>
`.trim()
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"games",
"boardgames"
],
"engines": {
"node": "12.x"
},
"author": "Mikko Saari",
"license": "MIT",
"dependencies": {
Expand Down
10 changes: 2 additions & 8 deletions rest/post_game.rest
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
2 changes: 1 addition & 1 deletion routes/18sh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
})
}

0 comments on commit f2efd2c

Please sign in to comment.