Added stats api route
This commit is contained in:
parent
d51c58867d
commit
c89f2a2939
|
@ -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
|
//Get url api route
|
||||||
fastify.get('/api/:shortcode', async (req, res) => {
|
fastify.get('/api/:shortcode', async (req, res) => {
|
||||||
const shortcode = req.params.shortcode;
|
const shortcode = req.params.shortcode;
|
||||||
|
@ -168,6 +182,7 @@ fastify.get('/api/:shortcode', async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//User registration
|
//User registration
|
||||||
fastify.post('/api/register', async (req, res) => {
|
fastify.post('/api/register', async (req, res) => {
|
||||||
if (!config.registrationEnabled) {
|
if (!config.registrationEnabled) {
|
||||||
|
|
Loading…
Reference in New Issue