-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added proxy for elasticsearch requests
Strings are now properly sanitized before being sent to the elasticsearch server. Since this API endpoint is on the same domain, this also removes the requirement to allow CORS in elasticsearch. Closes #1
- Loading branch information
Showing
6 changed files
with
36 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Router } from 'express'; | ||
import fetch from '../core/fetch'; | ||
import escapeElastic from 'elasticsearch-sanitize'; | ||
|
||
const router = new Router(); | ||
|
||
router.get('/', async (req, res, next) => { | ||
try { | ||
const q = encodeURIComponent(escapeElastic(req.query.q)); | ||
const searchUrl = 'http://localhost:9200/seinfeld/_search?q=text:' + q; | ||
const response = await fetch(searchUrl); | ||
const content = await response.json(); | ||
const results = content.hits.hits.map(function getResultObject(hit) { | ||
return hit._source; | ||
}); | ||
res.status(200).send({ results }); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}); | ||
|
||
export default router; |
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
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
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