add json and router koa modules
This commit is contained in:
parent
13ca85c1c7
commit
da3bd0695e
|
@ -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",
|
||||
|
|
23
src/index.js
23
src/index.js
|
@ -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}/`)
|
||||
|
|
Loading…
Reference in New Issue