add json and router koa modules

This commit is contained in:
Jakub Sokołowski 2018-10-16 13:31:16 -04:00
parent 13ca85c1c7
commit da3bd0695e
2 changed files with 21 additions and 6 deletions

View File

@ -5,7 +5,9 @@
"main": "index.js",
"dependencies": {
"ioredis": "^4.1.0",
"koa": "^2.5.3"
"koa": "^2.5.3",
"koa-json": "^2.0.2",
"koa-router": "^7.4.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",

View File

@ -1,12 +1,25 @@
const Koa = require('koa');
const app = new Koa();
const Koa = require('koa')
const Router = require('koa-router')
const JSON = require('koa-json')
/* DEFAULTS */
let LISTEN_PORT = 3000
app.use(async ctx => {
ctx.body = 'Hello World';
const app = new Koa()
const router = new Router()
router.put('/click', async ctx => {
ctx.body = { 'resp': 'Hello World' }
});
app.listen(LISTEN_PORT);
router.get('/clicks', async ctx => {
ctx.body = { 'resp': 'Hello World' }
});
app.use(JSON({pretty: true}))
.use(router.routes())
.use(router.allowedMethods())
app.listen(LISTEN_PORT)
console.log(`Started at: http://localhost:${LISTEN_PORT}/`)