Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
msaari committed Jul 8, 2019
0 parents commit a24aea7
Show file tree
Hide file tree
Showing 7 changed files with 3,158 additions and 0 deletions.
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const Koa = require("koa")
const bodyParser = require("koa-bodyparser")
const Router = require("koa-router")

const app = new Koa()
app.use(bodyParser())

app.use(async (ctx, next) => {
try {
await next()
} catch (err) {
ctx.status = err.status || 500
ctx.body = err.message
ctx.app.emit("error", err, ctx)
}
})

app.on("error", (err, ctx) => {
if (err.name === "CastError") {
ctx.status = 400
} else {
console.error(err)
}
})

const router = new Router({
prefix: "/18sh"
})

require("./routes/18sh")({ router })

app.use(router.routes())
app.use(router.allowedMethods())

if (!module.parent) app.listen(3018)

module.exports = app
55 changes: 55 additions & 0 deletions modules/gameFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"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 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 cashHTML = cashHoldings.join("")

const topBarContent = `
Pro tip: Zoom in in the browser until the boxes fill up screen nicely.
`.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>`
}
Loading

0 comments on commit a24aea7

Please sign in to comment.