-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
49 lines (42 loc) · 970 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const fs = require('fs'),
path = require('path'),
constants = require('./constants')
function getLanguageJSON(language)
{
return JSON.parse(fs.readFileSync(path.join(constants.LANGUAGES_PATH, language + '.json')))
}
function getLanguages()
{
let langs = []
fs.readdirSync(constants.LANGUAGES_PATH).forEach(file => {
langs.push(path.parse(file).name)
})
return langs
}
function addLanguagesRoute(app)
{
app.get('/languages', (req,res) => {
res.json(getLanguages())
})
}
function addSummaryRoutes(app)
{
getLanguages().forEach(language => {
app.get('/' + language, (req, res) => {
res.render('resume', getLanguageJSON(language))
})
})
}
function addIndexRoute(app)
{
app.get('/', (req, res) => {
res.render('index')
})
}
function addRoutes(app)
{
addIndexRoute(app)
addLanguagesRoute(app)
addSummaryRoutes(app)
}
module.exports.addRoutes = addRoutes