Last active
January 28, 2016 04:25
-
-
Save softwarerero/a8a2a2b7de5389dcc226 to your computer and use it in GitHub Desktop.
Trying to use elasticsearch from a koa app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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