diff --git a/src/server.js b/src/server.js index 2bdc17c..59c3f34 100644 --- a/src/server.js +++ b/src/server.js @@ -139,6 +139,20 @@ fastify.post('/api', { newUrlSchema }, async (req, res) => { } }); +//Get stats api route +fastify.get('/api/stats', async (req, res) => { + const urls = await knex.select('shortcode') + .from('urls'); + + const visits = await knex.select('timestamp') + .from('visits'); + + return { + urls: urls.length, + visits: visits.length, + } +}); + //Get url api route fastify.get('/api/:shortcode', async (req, res) => { const shortcode = req.params.shortcode; @@ -168,6 +182,7 @@ fastify.get('/api/:shortcode', async (req, res) => { } }); + //User registration fastify.post('/api/register', async (req, res) => { if (!config.registrationEnabled) {