I'm working on a basic link redirector project.
Currently, I have set up an Express server in the following way:
const express = require('express');
const app = express()
const path = require('path');
const json = require('awesome-json')
app.get('/', (req, res) => res.send('henlo!'))
app.get('/:short', (req, res) => {
var short = req.params.short
json.read('redirect', (err, contents) => {
for(var i in contents) {
if(i == short) res.redirect(contents.git)
}
})
})
app.listen(1337, () => console.log('henlo'))
The JSON file I am using has the following structure:
{"git":"https://github.com/"}
In case the i
variable matches with the content, I want to extract the corresponding link.
Any guidance on how to achieve this would be much appreciated!