<commit_before>var index = require('./routes/index.js');
var home = require('./routes/home.js');
var upload = require('./routes/upload.js');
var view = require('./routes/view.js');
var auth = require('./routes/auth.js');
var register = require('./routes/register.js');
var login = require('./routes/login.js');
var panel = require('./routes/panel');

var fs = require('fs');
var path = require('path');
var jwt = require('express-jwt');
var jwtauth = jwt({
    secret: fs.readFileSync(path.join(__dirname, '../jwt.pem'), 'utf8'),
    userProperty: 'payload',
    getToken: function(req) {
        if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
            // First check Authorization header
            return req.headers.authorization.split(' ')[1];
        } else if (req.cookies && req.cookies['shimapan-token']) {
            // Get from cookies as fallback
            return req.cookies['shimapan-token'];
        }

        // no token received
        return null;
    }
});

module.exports = function(app) {
    app.use('/', index);
    app.use('/home', home);
    app.use('/v', view);
    app.use('/api/upload', jwtauth, upload);
    app.use('/api/auth', auth);
    app.use('/register', register);
    app.use('/login', login);
    app.use('/panel', jwtauth, panel);
    app.use('/panel*', jwtauth, panel);

    app.use(function(err, req, res, next) {
        if (err.name === 'UnauthorizedError') {
            res.status(401);
            res.json({"message": err.name + ": " + err.message});
        }
    })
};<commit_msg>Proper auth requirements to some pages<commit_after>var index = require('./routes/index.js');
var home = require('./routes/home.js');
var upload = require('./routes/upload.js');
var view = require('./routes/view.js');
var auth = require('./routes/auth.js');
var register = require('./routes/register.js');
var login = require('./routes/login.js');
var panel = require('./routes/panel');

var fs = require('fs');
var path = require('path');
var jwt = require('express-jwt');
var jwtauth = jwt({
    secret: fs.readFileSync(path.join(__dirname, '../jwt.pem'), 'utf8'),
    userProperty: 'payload',
    getToken: function(req) {
        if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
            // First check Authorization header
            return req.headers.authorization.split(' ')[1];
        } else if (req.cookies && req.cookies['shimapan-token']) {
            // Get from cookies as fallback
            return req.cookies['shimapan-token'];
        }

        // no token received
        return null;
    }
});

module.exports = function(app) {
    app.use('/', index);
    app.use('/home', jwtauth, home);
    app.use('/v', view);
    app.use('/api/upload', jwtauth, upload);
    app.use('/api/auth', auth);
    app.use('/register', register);
    app.use('/login', login);
    app.use('/panel', jwtauth, panel);
    app.use('/panel*', jwtauth, panel);

    app.use(function(err, req, res, next) {
        if (err.name === 'UnauthorizedError') {
            res.status(401);
            res.redirect('/login');
            res.json({"message": err.name + ": " + err.message});
        }
    })
};
{'fraction_non_alphanumeric': 0.19950433705080545, 'fraction_numerical': 0.0037174721189591076, 'mean_word_length': 2.7634032634032635, 'pattern_counts': {'":': 4, '<': 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': '4770861', 'n_tokens_mistral': 1012, 'n_tokens_neox': 1017, 'n_words': 219}