about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index.js25
-rw-r--r--src/index.test.js12
2 files changed, 37 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js
index e69de29..9ba74de 100644
--- a/src/index.js
+++ b/src/index.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const PORT = process.env.PORT || 3000
+
+const Koa = require('koa')
+const app = new Koa()
+
+const Router = require('koa-router')
+const router = new Router()
+
+router.get('/', function (ctx, next) {
+  ctx.status = 200
+  ctx.body = 'hello world'
+  next()
+})
+
+app.use(router.routes()).use(router.allowedMethods())
+
+module.exports = app
+
+if (require.main === module) {
+  app.listen(PORT, () => {
+    console.log(`App listening on port ${PORT}`)
+  })
+}
diff --git a/src/index.test.js b/src/index.test.js
new file mode 100644
index 0000000..2c11d65
--- /dev/null
+++ b/src/index.test.js
@@ -0,0 +1,12 @@
+const test = require('ava')
+const request = require('supertest')
+
+const app = require('./index.js')
+
+test(t =>
+  request(app.listen())
+    .get('/')
+    .expect(200)
+    .expect(/hello world/)
+    .then(() => t.pass())
+)