/docs -> /documents; documents router refactoring

This commit is contained in:
tmshv committed 2016-02-24 18:02:52 +03:00
1 parent 5244beecf8
commit c426e5a8d8
3 files changed
+15 -30

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ export default [
},
{
"text": "Документы",
"url": "/docs",
"url": "/documents",
"color": "yellow"
}
]
+14 -24
View File
@@ -1,42 +1,32 @@
/**
* Created by tmshv on 22/11/14.
*/
import co from 'co';
import route from 'koa-route';
import router from './';
import {index, json} from './';
import db from '../core/db';
export default function (app) {
[
[
'/documents',
router.accepts({
'text/html': router.index(),
'text/plain': router.index(),
'application/json': function *() {
let query = {};
this.body = yield db.c('documents')
.find(query)
.toArray();
}
json(function *() {
let query = {};
this.body = yield db.c('documents')
.find(query)
.toArray();
})
],
[
'/documents/:type',
router.accepts({
'text/html': router.index(),
'text/plain': router.index(),
'application/json': function *(type) {
this.body = yield db.c(type)
.find()
.toArray();
}
json(function *(type) {
this.body = yield db.c(type)
.find()
.toArray();
})
],
[
'/document/:doc',
index('../templates/document.html')
]
].forEach(item => {
//let {path, fn} = item;
let [path, fn] = item;
app.use(route.get(path, fn));
});
-5
View File
@@ -65,11 +65,6 @@ app.use(function *(next) {
app.use(route.get('/', routes.index()));
app.use(route.get('/team', routes.index()));
app.use(route.get('/docs', routes.index()));
app.use(route.get('/document/:doc', routes.index(
path.join(__dirname, 'templates/document.html')
)));
sitemap(app);
schedule(app);