UNPKG

crypto-slots

Version:

A minimal test server is provided, see server

39 lines (31 loc) 1.01 kB
import Koa from 'koa' import Router from '@koa/router' import config from './../client/slots/config.js' import { readFileSync } from 'fs' import staticKoa from 'koa-static' const server = new Koa() const router = new Router() server.use(staticKoa('./www/')) router.get('/', async ctx => { ctx.body = readFileSync('./www/index.html').toString() ctx.type = 'html/text' ctx.status = 200 }) router.get('/index.html', async ctx => { ctx.body = readFileSync('./www/index.html').toString() // ctx.type = 'html/text' // ctx.status = 200 }) router.get('/spin', async ctx => { const result = [] const game = ctx.params.game; if (!game) throw new Error(404, 'game not defined.') else for (var i = 0; i < config[game].columns; i++) { result.push(lottery(3, config[game].slots.length)) } ctx.body = result }) server.use(router.routes()) server.use(router.allowedMethods()) server.on('error', error => console.error({error})) server.listen(5000)