简体   繁体   中英

External request in Runkit endpoint

Runkit ( https://runkit.com ), has a service where you can publish endpoints.

I am looking to publish an enpoint that calls an external server for data, and returns that data. It seems as though I am unable to accomplish this. Here's what I've tried:

var got = require("got");

var githubStatusJson = (await got("https://status.github.com/api/status.json", { json : true })).body;

exports.endpoint = function(request, response) {
    response.end("Hello world!");
}

The error message I am getting is :

{
error: "invalid_server",
message: "The requested document does not export an 'endpoint' function. Read more about endpoint: https://runkit.com/docs/endpoint"
}

Got a response from the runkit team that works!

const getJSON = require("async-get-json");
const getGitHubAPIStatus = getJSON("https://status.github.com/api/status.json");

module.exports.endpoint = async function (request, response)
{
    response.end(JSON.stringify(await getGitHubAPIStatus));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM