-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.js
More file actions
31 lines (24 loc) · 852 Bytes
/
dev-server.js
File metadata and controls
31 lines (24 loc) · 852 Bytes
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
const buildProfiles = require('./scripts/profiles');
const buildVotes = require('./scripts/votes');
const express = require('express');
const app = express();
let profilesPromise = buildProfiles('./src/data/profiles');
let votesPromise = profilesPromise.then(async (profiles) => {
let nameMap = new Map(profiles.map(p => [p.fullName.split(' ').pop(), p.fullName]));
return await buildVotes('./src/data/votes.tsv', nameMap);
});
app.use(express.static('src/'));
app.get('/', (_, res) => res.redirect('/index.html'));
app.get('/content/profiles.json', (_, res) => {
profilesPromise.then(profiles => {
res.send(profiles);
});
});
app.get('/content/votes.json', (_, res) => {
votesPromise.then(votes => {
res.send(votes);
})
});
app.listen(8080, () => {
console.log('Development server started on http://localhost:8080/');
});