forked from hemanth/koa-rest
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
36 lines (29 loc) · 953 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var books = require('./controllers/books');
var compress = require('koa-compress');
var logger = require('koa-logger');
var serve = require('koa-static');
var route = require('koa-route');
var koa = require('koa');
var path = require('path');
var app = module.exports = koa();
// Logger
app.use(logger());
app.use(route.get('/', books.home));
app.use(route.get('/books/', books.all));
app.use(route.get('/view/books/', books.list));
app.use(route.get('/books/:id', books.fetch));
app.use(route.post('/books/', books.add));
app.use(route.put('/books/:id', books.modify));
app.use(route.delete('/books/:id', books.remove));
app.use(route.options('/', books.options));
app.use(route.trace('/', books.trace));
app.use(route.head('/', books.head));
// Serve static files
app.use(serve(path.join(__dirname, 'public')));
// Compress
app.use(compress());
if (!module.parent) {
app.listen(1337);
console.log('listening on port 1337');
}