0
我試圖創建一個簡單的鏈接重新導演。從for循環獲取JSON對象
我有一個Express服務器上運行,像這樣:
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'))
我的JSON文件看起來像這樣
{"git":"https://github.com/"}
如果i
變量匹配的內容,我將如何得到的鏈接?
預先感謝您!