export default function (app, config) { if (!config.debug) { //response-time app.use(responseTime()); //logger app.use(logger()); } //Compress all things app.use(compress({ threshold: 2048, flush: require('zlib').Z_SYNC_FLUSH })); //json response app.use(jsonResp()); //serve static files config.path.static.forEach(function (item) { app.use(serve(item.path, item.options)); }); // favicon app.use(favicon(config.path.favicon)); //on-error //onerror(app, config.onerror); };
var fs = require('fs') var app = koa() //Add database si = database.getSequelizeInstance() si.sync() var nodeCtrl = require('./controller/node') //REMOVE IN PRODUCTION?? swig.setDefaults(config.templateOptions) //ROUTES app.keys = [config.sessionSecret] app.use(session()) app.use(jsonResp()) app.use(router(app)) //PAGE ROUTES app.get('/', defaultPageLoad('index')) app.get('/about', defaultPageLoad('about')) app.get('/node/:id', defaultPageLoad('index')) app.get('/public/*', serve('.')) //API ROUTES app.get('/api/node/:id/children', nodeCtrl.getChildren) app.get('/api/node/:id', nodeCtrl.get) app.post('/api/node', nodeCtrl.post) //PAGE HANDLERS function defaultPageLoad(pageName, requiresLogin) {