2

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"
}
user2202911
  • 2,898
  • 5
  • 20
  • 28

1 Answers1

2

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));
}
user2202911
  • 2,898
  • 5
  • 20
  • 28
  • Current implementation "cached" the promise result. It's better to create the requested promise inside the function so the promise will actually get fetch the JSON each request. – Moshe Simantov Jan 16 '20 at 15:00