diff options
author | Alan Pearce | 2017-06-18 00:28:24 +0200 |
---|---|---|
committer | Alan Pearce | 2017-06-18 00:28:24 +0200 |
commit | 1d8c3484540f2bf5fa70eed2485df0b03efafa5b (patch) | |
tree | 0e223346fe7fb12cc93193083871588d7c073116 /src | |
parent | 6815f5e27a18eddad8862a6e8fbac1c7e2fefcd7 (diff) | |
download | homestead-1d8c3484540f2bf5fa70eed2485df0b03efafa5b.tar.lz homestead-1d8c3484540f2bf5fa70eed2485df0b03efafa5b.tar.zst homestead-1d8c3484540f2bf5fa70eed2485df0b03efafa5b.zip |
feat: setup basic web server
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 25 | ||||
-rw-r--r-- | src/index.test.js | 12 |
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()) +) |