Giter Club home page Giter Club logo

Comments (2)

karakanb avatar karakanb commented on September 13, 2024 1

Hey, sorry, I missed this issue before.

Unfortunately, I won't be opening the backend source code because it is around ~50 lines of code that consists of a couple of functions that contain security tokens and stuff like that, so there is no value in that. However, if you are looking for parsers, I have already open-sourced them:

You can install them with NPM and expose them via a simple HTTP server. In the end, assuming you have a method to run HTTP GET requests, you can deploy your API with literally 3 lines of code: get the HTML, pass it to the parser, return the response.


In fact, I tried to gather the pieces to a single file and remove the details, and below is what the API looks like, as you can see the majority of the code is boilerplate, and the core API handler is a single method call, and it is not even the best way to write it probably. I haven't tested the below, sharing just to give you all an idea.

const https = require('https');
const ghParser = require('gh-trending-parser');

function httpsGet(url, successCallback, errorCallback) {
  var req = https.get(url, function (res) {
    var output = '';
    res.setEncoding('utf8');

    res.on('data', function (chunk) {
      output += chunk;
    });

    res.on('end', () => {
      successCallback(output);
    });
  });

  req.on('error', (err) => {
    errorCallback(err);
  });
}

function response(statusCode, data) {
  return {
    statusCode,
    headers: {
      "Access-Control-Allow-Origin": "*"
    },
    body: JSON.stringify({
      success: statusCode === 200,
      data,
    }),
  }
}

module.exports.github = (event, context, callback) => {
  httpsGet(
    'https://github.com/trending',
    output => callback(null, response(200, ghParser.parse(output))),
    err => callback(null, response(500, err.message))
  );
};

from devo.

greko6 avatar greko6 commented on September 13, 2024

What's the verdict? :)

from devo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.