const express = require('express'); const index = express.Router(); const Url = require('../models/Url'); index.get('/', async (req, res) => { res.sendFile('index.html', { root: './' }) }); index.get('/docs', async (req, res) => { res.sendFile('docs.html', { root: './' }) }); index.get('/:urlId', async (req, res) => { try { const url = await Url.findOne({ urlId: req.params.urlId }); if (url) { url.clicks++; url.save(); return res.redirect(url.origUrl); } else res.status(404).json('Not found'); } catch (err) { console.log(err); res.status(500).json('Server Error 2'); } }); module.exports = index;