Repository navigation
Expand file tree
/
Copy pathwebServer.js
More file actions
77 lines (62 loc) · 2.3 KB
/
Copy pathwebServer.js
File metadata and controls
77 lines (62 loc) · 2.3 KB
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
69
70
71
72
73
74
75
76
77
import express from "express"
import { dirname, join } from "path"
import { fileURLToPath } from "url"
import congress from "./congressAPI.js"
const app = express()
const __dirname = dirname(fileURLToPath(import.meta.url))
app.use(express.static(join(__dirname, "static")))
app.get("/", (_, res) => res.sendFile(`${__dirname}/home.html`))
app.get("/members", (_, res) => res.sendFile(`${__dirname}/members.html`))
app.get("/members/:chamber/all", (req, res) => {
if(req.params.chamber === "house") {
res.sendFile(`${__dirname}/allMembersHouse.html`)
}
else if(req.params.chamber === "senate") {
res.sendFile(`${__dirname}/allMembersSenate.html`)
}
})
app.get("/members/latest", (_, res) => res.sendFile(`${__dirname}/newMembers.html`))
app.get("/bills/latest", (_, res) => res.sendFile(`${__dirname}/newBills.html`))
app.get("/member", (_, res) => res.sendFile(`${__dirname}/specificMember.html`))
app.get("/bill", (_, res) => res.sendFile(`${__dirname}/specificBill.html`))
app.get("/api/latest/members", (req, res) => {
congress.getLatestMembers()
.then(response => response.results[0])
.then(response => res.json(response))
})
app.get("/api/latest/bills", (req, res) => {
congress.getLatestBills()
.then(response => response.results[0])
.then(response => res.json(response))
})
app.get("/api/members/:chamber/:state", (req, res) => {
if(req.params.chamber === "house") {
congress.getStateReps(req.params.state)
.then(response => res.json(response))
}
else if(req.params.chamber === "senate") {
congress.getStateSenators(req.params.state)
.then(response => res.json(response))
}
else {
res.redirect("/404")
}
})
app.get("/api/members/:chamber", (req, res) => {
if(req.params.chamber === "house" || req.params.chamber === "senate") {
congress.getAllMembers(req.params.chamber)
.then(response => res.json(response))
}
else {
res.redirect("/404")
}
})
app.get("/api/member/:memberID", (req, res) => {
congress.getCongressMember(req.params.memberID)
.then(response => res.json(response))
})
app.get("/api/bill/:billID", (req, res) => {
congress.getBill(req.params.billID)
.then(response => res.json(response))
})
app.listen(80)