Created
November 14, 2018 20:04
-
-
Save underoot/d8c726fc5e2707d2d9a3db0e33f2ce55 to your computer and use it in GitHub Desktop.
Async Template Tag
This file contains hidden or 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
'use strict'; | |
const got = require('got'); | |
const express = require('express'); | |
const app = express(); | |
const html = (body) => ({ | |
fillSearch: (value) => html(body.replace( | |
'id="text"', `id="text" value="${value}"` | |
)), | |
toString: () => body | |
}); | |
const search = async (parts) => ( | |
html((await got('https://ya.ru')).body).fillSearch(parts.join('')).toString() | |
); | |
app | |
.get('/', async (req, res) => { | |
res.send(await search`ВВП`); | |
}) | |
.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment