diff --git a/src/server.js b/src/server.js index 467fc14..b279410 100644 --- a/src/server.js +++ b/src/server.js @@ -2,6 +2,7 @@ const fastify = require('fastify')({ logger: true }) var uniqid = require('uniqid'); require('dotenv').config(); const argon2 = require('argon2'); +const isBot = require('isbot') let config = { domain: process.env.DOMAIN || "localhost:3000", @@ -74,27 +75,23 @@ fastify.decorate('verifyJWT', function async(request, reply, done) { //Automagic Amazn redirects on /a/ fastify.get('/a/:id', async (req, res) => { - res.header("X-Robots-Tag","noindex, nofollow"); res.redirect(302, `https://amazon.de/dp/${req.params.id}`) await knex('visits').insert({ shortcode: req.params.id, provider: 'a' }); }) //Automagic Youtube redirects on /yt/ fastify.get('/yt/:id', async (req, res) => { - res.header("X-Robots-Tag","noindex, nofollow"); res.redirect(302, `https://youtu.be/${req.params.id}`) await knex('visits').insert({ shortcode: req.params.id, provider: 'yt' }); }) //Automagic Youtube Playlist redirects on /ytpl/ fastify.get('/ytpl/:id', async (req, res) => { - res.header("X-Robots-Tag","noindex, nofollow"); res.redirect(302, `https://youtube.com/playlist?list=${req.params.id}`) await knex('visits').insert({ shortcode: req.params.id, provider: 'ytpl' }); }) //Automagic ebay item redirects on /e/ fastify.get('/e/:id', async (req, res) => { - res.header("X-Robots-Tag","noindex, nofollow"); res.redirect(302, `https://ebay.de/itm/${req.params.id}`) await knex('visits').insert({ shortcode: req.params.id, provider: 'e' }); }) @@ -114,6 +111,10 @@ fastify.get('/:shortcode', async (req, res) => { if (!target[0]) { return 404 } + if(isBot(req.headers['user-agent'])){ + return "Bad Bot!" + } + res.redirect(302, target[0].target); await knex('visits').insert({ shortcode, provider: 'native' }); })