-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
80 lines (70 loc) · 2.07 KB
/
server.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
69
70
71
72
73
74
75
76
77
78
79
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import fs from "fs";
import path from "path";
dotenv.config();
// Initialize App
const app = express();
app.use(cors());
const __dirname = path.resolve();
app.get('/UF/', (req, res) => {
res.header("Content-Type",'application/json');
const sickImmunizer = req.query.sickImmunizer;
const local = req.query.local;
if (sickImmunizer) {
if (sickImmunizer.includes(",")) {
const result = {};
for (let arg of sickImmunizer.split(",")) {
result[arg] =
JSON.parse(fs.readFileSync(
path.join(
__dirname,
`./api/UF/${local}/sicks/${arg}.json`
)
));
}
res.send(result);
} else {
res.sendFile(path.join(__dirname, `./api/UF/${local}/sicks/${sickImmunizer}.json`));
}
return;
}
const citiesAcronym = req.query.citiesAcronym;
res.sendFile(path.join(__dirname, `./api/UF/${local}/${citiesAcronym}.json`));
});
app.get('/:arg', (req, res) => {
res.header("Content-Type",'application/json');
res.sendFile(path.join(__dirname, `./api/${req.params.arg}.json`));
});
app.get('/', (req, res) => {
res.header("Content-Type",'application/json');
const sickImmunizer = req.query.sickImmunizer;
if (sickImmunizer) {
if (sickImmunizer.includes(",")) {
const sickImmunizers = sickImmunizer.split(",");
const result = {};
for (let arg of sickImmunizers) {
result[arg] =
JSON.parse(fs.readFileSync(
path.join(
__dirname,
`./api/sicks/${arg}.json`
)
));
}
res.send(result);
} else {
res.sendFile(path.join(__dirname, `./api/sicks/${req.query.sickImmunizer}.json`));
}
return;
}
const citiesAcronym = req.query.citiesAcronym;
if (citiesAcronym) {
res.sendFile(path.join(__dirname, `./api/${'citiesAcronym' + citiesAcronym}.json`));
}
});
const port = process.env.SERVER_HOST_PORT;
app.listen(port, () => {
console.log(`\nServer started at ${port}!\n`);
});