-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 1.12 KB
/
index.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
require('dotenv').config()
const express = require('express')
const cors = require('cors')
const app = express()
const port = process.env.PORT | 3000
const { defaultEndpoint } = require('./defaultEndpoint')
const { sendQueryWeb } = require('./sendQuery')
const { cancelQueryWeb } = require('./cancelQuery')
const { getTokenWeb } = require('./getToken')
const { getQueryStatusWeb } = require('./getQueryStatus')
const { getQueryResultsWeb } = require('./getQueryResults')
// Init globals
global.uuidToUser = {}
const endpoints = [
['/', defaultEndpoint],
['/sendQuery', sendQueryWeb],
['/cancelQuery', cancelQueryWeb],
['/getToken', getTokenWeb],
['/getQueryStatus', getQueryStatusWeb],
['/getQueryResults', getQueryResultsWeb],
];
app.options('*',cors());
app.use(express.json());
app.get(endpoints[0][0], (req,res) => {
endpoints[0][1](req,res)
});
endpoints.forEach(element => {
console.log("Registering", element[0], element[1])
app.post(element[0], cors(), (req, res) => {
element[1](req, res);
})
});
app.listen(port, () => {
console.log(`shrooms-v2-backend app listening on port ${port}`)
});