export default function createFacebookMessengerBotApplication() { const app = koala() .use(cors()) .use(function* assertBaseUrl(next) { this.assert(process.env.VALIDATION_TOKEN, 500, 'Validation token missing.'); this.assert(process.env.PAGE_ACCESS_TOKEN, 500, 'Page access token missing.'); yield* next; }) .use(router.routes()) .use(router.allowedMethods()); app.name = 'fbmessenger:messenger'; return app; }
function App(domain) { if (global.app) throw new Error('Application already created.'); global.app = this; events.EventEmitter.call(this); if (config.server.koa) this.base = koa(); else this.base = koala({ session: false, fileServer: { root: config.server.static_path, index: true, hidden: true, maxage: config.server.static_max_age || 0 } }); this.domain = domain || null; }
const text = require('./lorem-ipsum') const koa = require('koala') const router = require('koa-router')() const app = koa() router.get('/', function *(next) { this.body = text }) router.get('/test', function *(next) { this.body = text }) // response app.use(router.routes()) app.use(router.allowedMethods()) app.listen(5005)