-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (38 loc) · 1.39 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
const CLIENT_ID = "587958545142-eeai3n1svhpndn1jvgfrsomd1djhcag5.apps.googleusercontent.com";
const express = require("express");
const bodyParser = require("body-parser");
const sqlite3 = require("sqlite3");
const {OAuth2Client} = require("google-auth-library");
const app = express();
const state = {};
const client = new OAuth2Client(CLIENT_ID);
async function getPayload(token) {
const ticket = await client.verifyIdToken({
idToken: token,
audience: CLIENT_ID
});
return ticket.getPayload();
}
state.getPayload = getPayload;
state.CLIENT_ID = CLIENT_ID;
state.db = new sqlite3.Database("./db/acm.db", err => {
console.log("Connected to database");
});
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const announcementRoutes = require('./routes/announcements');
const addAnnouncementRoutes = require("./routes/addAnnouncement");
const tokenSignIn = require("./routes/tokenSignIn");
const accounts = require("./routes/accounts");
const editAccount = require("./routes/editAccount");
const committees = require("./routes/committees");
app.use('/', announcementRoutes(state));
app.use("/", addAnnouncementRoutes(state));
app.use("/", tokenSignIn(state));
app.use("/", accounts(state));
app.use("/", editAccount(state));
app.use("/", committees(state));
const PORT = 5000;
app.listen(PORT,()=> {
console.log("server started on port: " + PORT);
});