-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
68 lines (52 loc) · 2.02 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const app = express();
const fs = require('fs').promises; // Using fs.promises for asynchronous file operations
app.use(express.static('public'));
const port = 3000;
// Set EJS as the view engine
app.set('view engine', 'ejs');
// Define a route to render an EJS template
app.get('/', (req, res) => {
res.render('commitee');
});
app.get('/map', async (req, res) => {
const geojsonData = await fs.readFile('public/S12000033-ward_GeoJSON.json');
res.render('map', { geojsonData });
});
app.get('/:info', async (req, res) => {
try {
// Read the JSON file asynchronously
const data = await fs.readFile('public/council_committee_JSON.json', 'utf8');
const jsonData = JSON.parse(data);
// Filter the data based on the parameter
const filteredData = jsonData.filter(item => item.Category === req.params.info);
// Send the filtered data as response
res.render('commitee_members', { filteredData });
} catch (err) {
console.error('Error reading file:', err);
res.status(500).send('Error reading file');
}
});
app.get('/:info/:commitee', async (req, res) => {
try {
// Read the JSON file asynchronously
const data = await fs.readFile('public/meetings.json', 'utf8');
const jsonData = JSON.parse(data);
// Filter the data based on the parameter
const trimmed_commitee_string = req.params.commitee.replace(/\s+/g, '');
const filteredData = jsonData.filter(item =>
{
const trimmed_string = item.name.replace(/\s+/g, '');
trimmed_string === trimmed_commitee_string
});
// Send the filtered data as response
res.render('individual_commitee.ejs', { filteredData });
} catch (err) {
console.error('Error reading file:', err);
res.status(500).send('Error reading file');
}
});
// Start the server
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});