summaryrefslogtreecommitdiff
path: root/server/js/apibay.js
blob: 9ef7326a4b681da596e1853ad2ec0f2f39bc60f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"use strict";

const https = require('https');

const server = 'https://apibay.org';

async function getRequest(url)
{
	let promise = new Promise( resolve => {
		let data = '';

		https.get(url, res => {
			res.on('data', chunk => {data += chunk});
			res.on('end', () => resolve(data));
		});
	});

	return await promise;
}

async function hit(query)
{
	return JSON.parse(await getRequest(server + '/q.php?q=' + encodeURI(query)));
}

module.exports = {hit};