<commit_before>const express = require('express');

const wp = require('./wikipedia_parse');


const app = express();
app.set('json spaces', 2); // Nice formatting for JSON outputs


// Cross-origin resource sharing allows client-side Javascript from other sites to use this API


app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});


// API endpoints


app.get('/links', (req, res) => {
  const page = req.query.page;
  wp.getPageHtml(page)
    .then(wp.getFirstParagraph)
    .then(wp.getWikiLinks)
    .then(links => res.send(links));
});

app.get('/pagename', (req, res) => {
  const page = req.query.page;
  wp.getPageName(page)
    .then(name => res.send(name));
});

app.get('/random', (req, res) => {
  wp.getRandomArticle()
    .then(page => res.send(page));
});

app.get('/suggest', (req, res) => {
  const text = req.query.text;
  wp.getSuggestions(text)
    .then(suggestions => res.send(suggestions));
});<commit_msg>Surround getPageName API responses in quotes so that they're JSON-parseable<commit_after>const express = require('express');

const wp = require('./wikipedia_parse');


const app = express();
app.set('json spaces', 2); // Nice formatting for JSON outputs


// Cross-origin resource sharing allows client-side Javascript from other sites to use this API


app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});


// API endpoints


app.get('/links', (req, res) => {
  const page = req.query.page;
  wp.getPageHtml(page)
    .then(wp.getFirstParagraph)
    .then(wp.getWikiLinks)
    .then(links => res.send(links));
});

app.get('/pagename', (req, res) => {
  const page = req.query.page;
  wp.getPageName(page)
    .then(name => res.send(`"${name}"`));
});

app.get('/random', (req, res) => {
  wp.getRandomArticle()
    .then(page => res.send(page));
});

app.get('/suggest', (req, res) => {
  const text = req.query.text;
  wp.getSuggestions(text)
    .then(suggestions => res.send(suggestions));
});
{'fraction_non_alphanumeric': 0.19187358916478556, 'fraction_numerical': 0.0009029345372460496, 'mean_word_length': 4.024943310657596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4348103', 'n_tokens_mistral': 772, 'n_tokens_neox': 738, 'n_words': 163}