<commit_before>var express = require('express');
var AuthApp = require('../index').app;
var secrets = require('../client_secrets');
var app = express();
var auth = new AuthApp(secrets, {appBaseUrl: "http://localhost:8088", secureCookies: false});
var debug = require('debug')('v1oauth');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var request = require('superagent');
var serverBaseUri = secrets.web.server_base_uri;

app.use(bodyParser());
app.use(cookieParser());

app.get("/index", auth.restrict, function (req, res) {
  debug('get /index');
  res.send('<?html?><html><head><title>index page</title></head><body>' +
    '<form method="post">' +
    '<textarea name="query" cols=80 rows=20>' +
    '{\n' +
    '  "from": "Member",\n' +
    '  "select": [\n' +
    '    "Name",\n' +
    '    "Nickname"\n' +
    '  ]\n' +
    '}' +
    '</textarea>' +
    '<button>Submit</button>' +
    '</form>' +
    '</body></html>');
});
app.post('/index', auth.restrict, function (req, res) {
  debug('post /index');
  var queryText = req.param('query');
  var queryObject = null;
  var token = req.cookies.v1accessToken;
  var pageRes = res;
  debug('getting url %s', serverBaseUri + '/query.v1');

  try {
    queryObject = JSON.parse(queryText);
  } catch (err) {
    if (err instanceof SyntaxError) {
      console.dir(err);
      renderResults(pageRes, queryText, 'syntax error in your JSON\n' + err.message);
    } else {
      throw err;
    }
  }
  if (queryObject) {
    request
      .get(serverBaseUri + '/query.v1')
      .set('Authorization', 'Bearer ' + token)
      .send(queryObject)
      .end(function (res) {
        var results;

        if (res.ok) {
          debug('successful request!');
          results = 'success!\n' + JSON.stringify(res.body, null, 2);
        } else {
          debug("failed to get data");
          results = 'failure :(\n' + res.text;
        }
        renderResults(pageRes, queryText, results);
      });
  }
});
function renderResults(res, queryText, results) {
  res.send('<?html?><html><head><title>index page</title></head><body>' +
    '<form method="post">' +
    '<textarea name="query" cols=80 rows=20>' +
    queryText +
    '</textarea>' +
    '<button>Submit</button>' +
    '</form>' +
    '<pre>' +
    results +
    '</pre>' +
    '</body></html>');
}
app.use(auth.router);<commit_msg>make demo a bit easier<commit_after>var express = require('express');
var AuthApp = require('../index').app;
var secrets = require('../client_secrets');
var app = express();
var auth = new AuthApp(secrets, {appBaseUrl: "http://localhost:8088", secureCookies: false});
var debug = require('debug')('v1oauth');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var request = require('superagent');
var serverBaseUri = secrets.web.server_base_uri;

app.use(bodyParser());
app.use(cookieParser());

app.get("/index", auth.restrict, function (req, res) {
  debug('get /index');
  res.send('<?html?><html><head><title>index page</title></head><body>' +
    '<form method="post">' +
    '<textarea name="query" cols=80 rows=20>' +
    '{\n' +
    '  "from": "Member",\n' +
    '  "select": [\n' +
    '    "Name",\n' +
    '    "Nickname"\n' +
    '  ]\n' +
    '}' +
    '</textarea>' +
    '<button>Submit</button>' +
    '</form>' +
    '</body></html>');
});
app.post('/index', auth.restrict, function (req, res) {
  debug('post /index');
  var queryText = req.param('query');
  var queryObject = null;
  var token = req.cookies.v1accessToken;
  var pageRes = res;
  debug('getting url %s', serverBaseUri + '/query.v1');

  try {
    queryObject = JSON.parse(queryText);
  } catch (err) {
    if (err instanceof SyntaxError) {
      console.dir(err);
      renderResults(pageRes, queryText, 'syntax error in your JSON\n' + err.message);
    } else {
      throw err;
    }
  }
  if (queryObject) {
    request
      .get(serverBaseUri + '/query.v1')
      .set('Authorization', 'Bearer ' + token)
      .send(queryObject)
      .end(function (res) {
        var results;

        if (res.ok) {
          debug('successful request!');
          results = 'success!\n' + JSON.stringify(res.body, null, 2);
        } else {
          debug("failed to get data");
          results = 'failure :(\n' + res.text;
        }
        renderResults(pageRes, queryText, results);
      });
  }
});
app.get('/', function(req, res) {
  res.redirect('/index');
});
function renderResults(res, queryText, results) {
  res.send('<?html?><html><head><title>index page</title></head><body>' +
    '<form method="post">' +
    '<textarea name="query" cols=80 rows=20>' +
    queryText +
    '</textarea>' +
    '<button>Submit</button>' +
    '</form>' +
    '<pre>' +
    results +
    '</pre>' +
    '</body></html>');
}
app.use(auth.router);
{'fraction_non_alphanumeric': 0.20400578154036755, 'fraction_numerical': 0.007020441874870948, 'mean_word_length': 3.06035205364627, 'pattern_counts': {'":': 4, '<': 67, '<?xml version=': 0, '>': 67, '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': '3248658', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1637, 'n_words': 335}