Loading index.js +1 −39 Original line number Original line Diff line number Diff line Loading @@ -26,44 +26,6 @@ connection.connect((err)=>{ } } }) }) /** * Get the authorization token from the request header * @param {import('express').Request} req * @param {import('express').Response} res * @param {import('mysql').Connection} sql * @param {Function} cb the callback function to call only if the token is valid. There are no parameters. */ function checkToken(req, res, sql, cb){ var auth = req.get('Authorization') if (!auth){ renderError(res, 403, 'No authorization token provided'); return false; } else { if (auth.includes('Basic ')){ var token = auth.replace('Basic ', '') sql.query("SELECT * FROM Auth WHERE token = ?", token, async (err, result)=>{ if (err){ console.error(err) renderError(res, 500, "Internal Server Error") } else { if (result.length < 1){ renderError(res, 401, "Authorization Token not found.") } else { if (result[0].validate == 0){ renderError(res, 403, "Authorization Token not validated.") } else { console.log('Connexion from '+ result[0].description); cb(); } } } }); } else { renderError(res, 403, "Token not found in Authorization header, please set a Token in Authorization header like this: 'Authorization: Basic [token]'.") } } } /** /** * Render a JSON response for an error * Render a JSON response for an error * @param {import('express').Response} res * @param {import('express').Response} res Loading Loading @@ -121,7 +83,7 @@ app.get('/', (req, res) => { }) }) fs.readdirSync(path.join(__dirname, 'route')).filter(file => file.endsWith('.js')).forEach(function(file) { fs.readdirSync(path.join(__dirname, 'route')).filter(file => file.endsWith('.js')).forEach(function(file) { require(path.join(__dirname, 'route', file))(app, connection, checkToken, renderError) require(path.join(__dirname, 'route', file))(app, connection, renderError) }); }); // catch 404 and forward to error handler // catch 404 and forward to error handler Loading route/getPlayerVote.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { const mapId = req.query.map || req.body.map, const mapId = req.query.map || req.body.map, player = req.query.player || req.body.player; player = req.query.player || req.body.player; Loading route/getVotes.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { const mapId = req.query.map || req.body.map; const mapId = req.query.map || req.body.map; if (!mapId) { if (!mapId) { Loading route/mostPlayerVoted.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { sql.query('SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC', (err, sqlRes)=>{ sql.query('SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC', (err, sqlRes)=>{ if (err) { if (err) { Loading route/mostVotedMaps.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { sql.query('SELECT map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC', (err, sqlRes)=>{ sql.query('SELECT map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC', (err, sqlRes)=>{ if (err) { if (err) { Loading Loading
index.js +1 −39 Original line number Original line Diff line number Diff line Loading @@ -26,44 +26,6 @@ connection.connect((err)=>{ } } }) }) /** * Get the authorization token from the request header * @param {import('express').Request} req * @param {import('express').Response} res * @param {import('mysql').Connection} sql * @param {Function} cb the callback function to call only if the token is valid. There are no parameters. */ function checkToken(req, res, sql, cb){ var auth = req.get('Authorization') if (!auth){ renderError(res, 403, 'No authorization token provided'); return false; } else { if (auth.includes('Basic ')){ var token = auth.replace('Basic ', '') sql.query("SELECT * FROM Auth WHERE token = ?", token, async (err, result)=>{ if (err){ console.error(err) renderError(res, 500, "Internal Server Error") } else { if (result.length < 1){ renderError(res, 401, "Authorization Token not found.") } else { if (result[0].validate == 0){ renderError(res, 403, "Authorization Token not validated.") } else { console.log('Connexion from '+ result[0].description); cb(); } } } }); } else { renderError(res, 403, "Token not found in Authorization header, please set a Token in Authorization header like this: 'Authorization: Basic [token]'.") } } } /** /** * Render a JSON response for an error * Render a JSON response for an error * @param {import('express').Response} res * @param {import('express').Response} res Loading Loading @@ -121,7 +83,7 @@ app.get('/', (req, res) => { }) }) fs.readdirSync(path.join(__dirname, 'route')).filter(file => file.endsWith('.js')).forEach(function(file) { fs.readdirSync(path.join(__dirname, 'route')).filter(file => file.endsWith('.js')).forEach(function(file) { require(path.join(__dirname, 'route', file))(app, connection, checkToken, renderError) require(path.join(__dirname, 'route', file))(app, connection, renderError) }); }); // catch 404 and forward to error handler // catch 404 and forward to error handler Loading
route/getPlayerVote.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { const mapId = req.query.map || req.body.map, const mapId = req.query.map || req.body.map, player = req.query.player || req.body.player; player = req.query.player || req.body.player; Loading
route/getVotes.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { const mapId = req.query.map || req.body.map; const mapId = req.query.map || req.body.map; if (!mapId) { if (!mapId) { Loading
route/mostPlayerVoted.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { sql.query('SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC', (err, sqlRes)=>{ sql.query('SELECT player, COUNT(*) AS votes FROM votes GROUP BY player ORDER BY votes DESC', (err, sqlRes)=>{ if (err) { if (err) { Loading
route/mostVotedMaps.js +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ const path = require('path'), * @param {import('express').Express} app * @param {import('express').Express} app * @param {import('mysql').Connection} sql * @param {import('mysql').Connection} sql */ */ module.exports = function(app, sql, token, errorHandler) { module.exports = function(app, sql, errorHandler) { app.get('/'+scriptName, function(req, res) { app.get('/'+scriptName, function(req, res) { sql.query('SELECT map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC', (err, sqlRes)=>{ sql.query('SELECT map, COUNT(*) AS votes FROM votes GROUP BY map ORDER BY votes DESC', (err, sqlRes)=>{ if (err) { if (err) { Loading