This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (60 loc) · 1.59 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
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
// ====
require('dotenv').config()
const logger = require("@bunnylogger/bunnylogger")
const express = require('express');
const app = express()
const port = process.env.SERVER_PORT || 3000
const cors = require('cors');
app.use(cors({
origin: '*'
}));
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const package = require("./package.json")
const cron = require('node-cron');
app.options('*', cors())
app.use(express.json());
const db = require("./modules/db")
const apiInfo = {
definition: {
openapi: '3.0.0',
info: {
title: package.name,
version: package.version,
},
},
apis: ['./*.js'],
};
const openapiSpecification = swaggerJsdoc(apiInfo);
// === Cache DB responce in ram for less reads ===
let zones = []
let markers = []
let contributors = []
async function readDB() {
zones = await db.read("zones")
markers = await db.read("tweets")
contributors = await db.read("contributors")
}
cron.schedule('* * * * *', () => {
readDB()
});
readDB()
// === Experss Endpoints ===
app.get("/", (req, res) => {
res.status(200).send("App Running")
})
app.get("/api", (req, res) => {
res.status(200).send(apiInfo.definition)
})
app.get("/api/markers", (req, res) => {
res.status(200).send(markers)
})
app.get("/api/zones", (req, res) => {
res.status(200).send(zones)
})
app.get("/api/contributors", (req, res) => {
res.status(200).send(contributors)
})
app.listen(port, () => {
logger.start(`Server running on ${process.env.SERVER_IP}:${process.env.SERVER_PORT}`)
})