"use strict";

function fetchjson(url) {
    return new Promise((resolve, reject) => {
        const headers = new Headers();
        headers.append("Accept", "application/json");
        fetch(url, { mode: "no-cors", headers })
            .then(r => r.json())
            .then(r => resolve(r))
            .catch(e => reject(e));
    });
}

function fetchtext(url) {
    const headers = new Headers();
    headers.append("Accept", "text/html");
    return new Promise((resolve, reject) => {
        fetch(url, { mode: "no-cors", headers })
            .then(r => r.text())
            .then(r => resolve(r))
            .catch(e => reject(e));
    });
}

module.exports = {
    fetchjson,
    fetchtext,
};