Added stats api route

This commit is contained in:
Nicolai Ort 2021-08-18 15:21:36 +02:00
parent d51c58867d
commit c89f2a2939
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 15 additions and 0 deletions

View File

@ -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) {