<commit_before>"use strict";

var express = require('express');
var app = express(),
  bodyParser = require('body-parser'),
  request = require('request'),
  ical2json = require("ical2json");

/* To Allow cross-domain Access-Control*/
var allowCrossDomain = function (req, res, next) {
  res.setHeader('Access-Control-Allow-Credentials', true);
  res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
  res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');

  // intercept OPTIONS method
  if ('OPTIONS' == req.method) {
    res.send(200);
  }
  else {
    next();
  }
};

app.use(allowCrossDomain);
// Parsing json and urlencoded requests
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(bodyParser.json({type: 'application/vnd.api+json'}));

app.get('/', function (req, res) {
  res.send("Server running...");
});


// API to validate ical url
app.post('/validate', function (req, res) {
  request(req.body.url, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      var data = ical2json.convert(body);
      if (data && data.VEVENT && data.VEVENT.length)
        res.send({'statusCode': 200});
      else
        res.send({'statusCode': 404});
    } else
      res.send({'statusCode': 500});
  })
});


// API to fetch events from an ical url
app.post('/events', function (req, res) {
  request(req.body.url, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      var data = ical2json.convert(body);
      if (data && data.VEVENT && data.VEVENT.length)
        res.send({'statusCode': 200, 'events': data.VEVENT});
      else
        res.send({'statusCode': 404, 'events': null});
    } else
      res.send({'statusCode': 500, 'events': null});
  })
});


var server = app.listen(3020, function () {
  var host = server.address().address;
  var port = server.address().port;<commit_msg>Added apis for fetching paginated list of events and single event from node proxy server<commit_after>"use strict";

var express = require('express');
var app = express(),
  bodyParser = require('body-parser'),
  request = require('request'),
  ical2json = require("ical2json");

/* To Allow cross-domain Access-Control*/
var allowCrossDomain = function (req, res, next) {
  res.setHeader('Access-Control-Allow-Credentials', true);
  res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
  res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');

  // intercept OPTIONS method
  if ('OPTIONS' == req.method) {
    res.send(200);
  }
  else {
    next();
  }
};

app.use(allowCrossDomain);
// Parsing json and urlencoded requests
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(bodyParser.json({type: 'application/vnd.api+json'}));

app.get('/', function (req, res) {
  res.send("Server running...");
});


// API to validate ical url
app.post('/validate', function (req, res) {
  if (req.body.url) {
    request(req.body.url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var data = ical2json.convert(body);
        if (data && data.VEVENT && data.VEVENT.length)
          res.send({'statusCode': 200});
        else
          res.send({'statusCode': 404});
      } else
        res.send({'statusCode': 500});
    });
  } else
    res.send({'statusCode': 500});
});


// API to fetch events from an ical url
app.post('/events', function (req, res) {
  var limit = req.body.limit || 20;
  var offset = req.body.offset || 0;
  if (req.body.url) {
    request(req.body.url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var data = ical2json.convert(body);
        if (data && data.VEVENT && data.VEVENT.length) {
          var paginatedListOfEvents = data.VEVENT.splice(offset, (offset + limit));
          res.send({'statusCode': 200, 'events': paginatedListOfEvents});
        }
        else
          res.send({'statusCode': 404, 'events': null});
      } else
        res.send({'statusCode': 500, 'events': null});
    });
  } else
    res.send({'statusCode': 500, 'events': null});
});


// API to fetch single event with given index from an ical url
app.post('/event', function (req, res) {
  var index = req.body.index || 0;
  if (req.body.url) {
    request(req.body.url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var data = ical2json.convert(body);
        if (data && data.VEVENT && data.VEVENT.length) {
          var event = data.VEVENT[index];
          res.send({'statusCode': 200, 'event': event});
        }
        else
          res.send({'statusCode': 404, 'event': null});
      } else
        res.send({'statusCode': 500, 'event': null});
    });
  } else
    res.send({'statusCode': 500, 'event': null});
});

var server = app.listen(3020, function () {
  var host = server.address().address;
  var port = server.address().port;
{'fraction_non_alphanumeric': 0.17762645914396888, 'fraction_numerical': 0.01867704280155642, 'mean_word_length': 3.338396624472574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3339005', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1625, 'n_words': 386}