+ documents router; other
This commit is contained in:
1 parent
56c1c9dffc
commit
fb0ae8148c
2 files changed
+49
-4
No files matched your search
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Created by tmshv on 22/11/14.
|
||||
*/
|
||||
|
||||
import co from 'co';
|
||||
import route from 'koa-route';
|
||||
import router 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();
|
||||
}
|
||||
})
|
||||
],
|
||||
[
|
||||
'/documents/:type',
|
||||
router.accepts({
|
||||
'text/html': router.index(),
|
||||
'text/plain': router.index(),
|
||||
'application/json': function *(type) {
|
||||
this.body = yield db.c(type)
|
||||
.find()
|
||||
.toArray();
|
||||
}
|
||||
})
|
||||
]
|
||||
|
||||
].forEach(item => {
|
||||
//let {path, fn} = item;
|
||||
let [path, fn] = item;
|
||||
app.use(route.get(path, fn));
|
||||
});
|
||||
};
|
||||
+6
-4
@@ -12,6 +12,7 @@ var bodyParser = require("koa-bodyparser");
|
||||
|
||||
var config = require("./config");
|
||||
var routes = require("./routes");
|
||||
import documents from './routes/documents';
|
||||
|
||||
var app = koa();
|
||||
app.proxy = true;
|
||||
@@ -24,10 +25,11 @@ app.use(etag());
|
||||
app.use(function *(next) {
|
||||
yield* next;
|
||||
|
||||
try{
|
||||
try {
|
||||
var xp = this.response.header['x-prerender'] == 'true';
|
||||
if(xp) this.body = this.body.replace('<meta name="fragment" content="!">', '');
|
||||
}catch(e){}
|
||||
if (xp) this.body = this.body.replace('<meta name="fragment" content="!">', '');
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
app.use(prerender(config.prerender));
|
||||
|
||||
@@ -66,7 +68,7 @@ require("./routes/sitemap")(app);
|
||||
require("./routes/schedule")(app);
|
||||
require("./routes/news")(app);
|
||||
require("./routes/gallery")(app);
|
||||
|
||||
documents(app);
|
||||
require("./instagram/router")(app);
|
||||
require("./instagram/io")(app);
|
||||
|
||||
|
||||
Reference in new issue
Block a user