Now logging visits to shorturls
This commit is contained in:
parent
5e9dec640a
commit
c4c22a7405
|
@ -1,9 +1,9 @@
|
|||
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable('visits', function (table) {
|
||||
table.increments('id').primary();
|
||||
table.timestamp('timestamp').defaultTo(knex.fn.now());
|
||||
table.string('shortcode');
|
||||
table.primary(['shortcode', 'timestamp']);
|
||||
table.foreign('shortcode').references('shortcode').inTable('urls');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -55,7 +55,8 @@ fastify.get('/:shortcode', async (req, res) => {
|
|||
if (!target[0]) {
|
||||
return 404
|
||||
}
|
||||
res.redirect(302, target[0].target)
|
||||
res.redirect(302, target[0].target);
|
||||
await knex('visits').insert({ shortcode });
|
||||
})
|
||||
|
||||
//Create new url schema
|
||||
|
|
Loading…
Reference in New Issue