forked from Ian-Bright/bls-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
32 lines (28 loc) · 1.12 KB
/
app.ts
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
import { initBigQuery } from './bigQuery';
import express, { Router } from 'express';
import { getAllQueryResults } from './controllers/query';
import cors from 'cors';
const app = express();
const router = Router();
const PORT = process.env.PORT || 8080;
app.use(cors({ credentials: true, origin: ['http://localhost:3000', 'https://wax-v1-analytics.vercel.app'] }));
app.listen(PORT, async () => {
initBigQuery();
console.log('Big query initialized 💿')
app.use('',
router.get('/queries', async (_req, res) => {
try {
const queryResults = await getAllQueryResults();
const resultObj = queryResults.reduce((obj, element) => {
obj[element.queryId] = element.results;
return obj;
}, {} as { [queryId: string]: any[] });
res.status(200).send(resultObj);
} catch (err) {
console.log('Error: ', err);
res.status(500).send('Error occurred');
}
})
);
return console.log(`🔥 Express is listening at http://localhost:${PORT} 🔥`);
});