Skip to content

Instantly share code, notes, and snippets.

@softwarerero
Last active January 28, 2016 04:25
Show Gist options
  • Save softwarerero/a8a2a2b7de5389dcc226 to your computer and use it in GitHub Desktop.
Save softwarerero/a8a2a2b7de5389dcc226 to your computer and use it in GitHub Desktop.
Trying to use elasticsearch from a koa app
var app, distDir, elClient, koa, path, router, send;
path = require('path');
send = require('koa-send');
router = require('koa-router')();
koa = require('koa');
app = koa();
elClient = new elasticsearch.Client({
log: 'error',
keepAlive: true
});
router.get('/api/what', function*(next) {
var genify, res, search;
genify = require('thunkify-wrap').genify;
search = genify(elClient.search);
res = (yield search({
index: 'my-index',
q: 'what'
}));
return this.body = {
answer: "you send " + res
};
});
app.use(router.routes());
distDir = __dirname + '/../client/dist';
app.use(function*(next) {
return (yield send(this, this.path, {
root: distDir
}));
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment