some console styling

master
Kit Kasune 1 year ago
parent dfb25f0d07
commit bf3add353d
  1. 5
      api/ani/v1/routes/series/add.js
  2. 5
      api/ani/v1/routes/user.js
  3. 11
      api/index.js

@ -110,9 +110,10 @@ module.exports = (app, router) => {
if (req.params.id.toLowerCase() === 'queue') {return next();} if (req.params.id.toLowerCase() === 'queue') {return next();}
return res.status(400).send("A series with that ID doesn't exist!"); return res.status(400).send("A series with that ID doesn't exist!");
} }
let {name, id, romaji, kanji, air, rating, likes, seasons, characters, altNames, genres, tags, nsfw, nsfwReason, synopsis, numericalId, completed, publishers, studios} = series; let {name, id, romaji, kanji, air, rating, likes, seasons, characters, altNames, genres, tags, nsfw, nsfwReason, numericalId, completed, publishers, studios} = series;
return res.json({ return res.json({
name, id, romaji, kanji, air, rating, likes, seasons, characters, altNames, genres, tags, nsfw, nsfwReason, synopsis, numericalId, completed, publishers, studios, name, id, romaji, kanji, air, rating, likes, seasons, characters, altNames, genres, tags, nsfw, nsfwReason, numericalId, completed, publishers, studios,
synopsis: {by: series.synopsis.by, synopsis: series.synopsis.synopsis},
meta: {completed: series.meta.completed, creator: series.meta.creator, locked: series.meta.locked} meta: {completed: series.meta.completed, creator: series.meta.creator, locked: series.meta.locked}
}); });
}); });

@ -49,10 +49,7 @@ module.exports = (app, router) => {
.catch(e => {console.error("Error trying to add new user", e); res.status(500).send("Something went wrong.");}); .catch(e => {console.error("Error trying to add new user", e); res.status(500).send("Something went wrong.");});
} }
catch (e) {console.error("Error trying to add new user", e); res.status(500).send("Something went wrong.");} catch (e) {console.error("Error trying to add new user", e); res.status(500).send("Something went wrong.");}
}) }); //TODO user editing
.put(app.auth.token, async (req, res) => {
});
router.route('/user/:id/auth') router.route('/user/:id/auth')
.post(async (req, res) => { .post(async (req, res) => {

@ -3,6 +3,7 @@ const bodyParser = require('body-parser');
const cors = require('cors'); const cors = require('cors');
const helmet = require('helmet'); const helmet = require('helmet');
const {set, createConnection} = require('mongoose'); const {set, createConnection} = require('mongoose');
const chalk = require('chalk');
const app = express(); const app = express();
set('strictQuery', false); set('strictQuery', false);
@ -48,9 +49,17 @@ server = app.listen(4062, async () => {
require('./v1/index')(app); //initialize bot API branch require('./v1/index')(app); //initialize bot API branch
require('./ani/index')(app); //initialize ani API branch require('./ani/index')(app); //initialize ani API branch
const reqTypeColors = {
GET: 'greenBright',
POST: 'blueBright',
PATCH: 'yellowBright',
PUT: 'yellow',
DELETE: 'redBright'
};
const checkMiddleware = (middleware, string) => { const checkMiddleware = (middleware, string) => {
if (middleware.route) {Object.keys(middleware.route.methods).forEach(method => { if (middleware.route) {Object.keys(middleware.route.methods).forEach(method => {
if (middleware.route.methods[method]) {console.log(`[${method.toUpperCase()}] ${string}${middleware.route.path}`);} if (middleware.route.methods[method]) {console.log(`${chalk.gray(`[`)}${chalk[reqTypeColors[method.toUpperCase()]](method.toUpperCase())}${chalk.gray(`]`)} ${string}${middleware.route.path}`);}
});} else if (middleware.name === 'router') {middleware.handle.stack.forEach(handler => {checkMiddleware(handler, string + middleware.handle.location);});} });} else if (middleware.name === 'router') {middleware.handle.stack.forEach(handler => {checkMiddleware(handler, string + middleware.handle.location);});}
}; };
app._router.stack.forEach(middleware => checkMiddleware(middleware, '')); //log all routes app._router.stack.forEach(middleware => checkMiddleware(middleware, '')); //log all routes

Loading…
Cancel
Save