-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
38 lines (29 loc) · 969 Bytes
/
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
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const {createClient} = require("redis");
const cors = require('cors')
const PORT = process.env.SERVER_PORT || 3002;
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.redis = createClient({url: process.env.REDIS_URL});
(async () => {
app.redis.on("error", (error) => console.error(`Redis: ${error}`));
await app.redis.connect();
})();
app.use(express.json());
const errorHandler = (err, req, res, next) => {
console.error(err);
const statusCode = res.statusCode === 200 ? 500 : res.statusCode;
res.status(statusCode).json({ error: err.message });
};
app.use(errorHandler);
app.get("/", (req, res) => {
res.json({ message: "Muon Fees API" });
});
require("./routes/fees.js")(app);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});