<commit_before>const bodyParser = require('body-parser');
const express = require('express');
const path = require('path');

const config = require('./config.json');
const pocket = require('./pocket.js');


const errorHandler = (res, err) => {
    res.status(500).send(err);
};

const url = `http://${config.address}:${config.port}`;

const app = express();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/www/html'));
app.use(express.static(path.join(__dirname, '/www')));
app.use(bodyParser.json());

app.post('/api/get', (req, res) => {
    pocket.get(req.body.accessToken, (data) => {
        res.setHeader('Content-Type', 'application/json');
        res.send(JSON.stringify(data));
    }, (err) => {
        errorHandler(res, err);
    });
});

app.get('/', (req, res) => {
    res.render('index', {
        'requestToken': pocket.getRequestToken(),
        'redirectURI': `${url}/app`
    });
});

app.get('/app', (req, res) => {
    pocket.authorize((data) => {
        res.render('app', {
            'accessToken': data.access_token,
            'username': data.username
        });
    }, (err) => {
        errorHandler(res, err);
    });
});

const start = () => {<commit_msg>server: redirect /app to / if not logged in<commit_after>const bodyParser = require('body-parser');
const express = require('express');
const path = require('path');

const config = require('./config.json');
const pocket = require('./pocket.js');


const errorHandler = (res, err) => {
    res.status(500).send(err);
};

const url = `http://${config.address}:${config.port}`;

const app = express();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/www/html'));
app.use(express.static(path.join(__dirname, '/www')));
app.use(bodyParser.json());

app.post('/api/get', (req, res) => {
    pocket.get(req.body.accessToken, (data) => {
        res.setHeader('Content-Type', 'application/json');
        res.send(JSON.stringify(data));
    }, (err) => {
        errorHandler(res, err);
    });
});

app.get('/', (req, res) => {
    res.render('index', {
        'requestToken': pocket.getRequestToken(),
        'redirectURI': `${url}/app`
    });
});

app.get('/app', (req, res) => {
    pocket.authorize((data) => {
        res.render('app', {
            'accessToken': data.access_token,
            'username': data.username
        });
    }, () => {
        res.redirect('/');
    });
});

const start = () => {
{'fraction_non_alphanumeric': 0.23020408163265307, 'fraction_numerical': 0.0024489795918367346, 'mean_word_length': 3.18259385665529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '615844', 'n_tokens_mistral': 799, 'n_tokens_neox': 794, 'n_words': 141}