-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (35 loc) · 1009 Bytes
/
Copy pathapp.js
File metadata and controls
45 lines (35 loc) · 1009 Bytes
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
import express from "express"
import dotenv from "dotenv"
import Database from "./database.js"
import { cors } from "./middleware.js"
import { getAllStuffDone } from "./api/update.js"
import content from "./data/html.js"
dotenv.config()
const app = express()
const PORT = process.env.PORT || 3003
new Database().start().then(() => {
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})
})
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
// API Routes
import country from "./api/country.js"
import update from "./api/update.js"
app.use("/api/country", cors, country)
app.use("/api/update", cors, update)
app.get("/", cors, (_, res) => {
res.status(200).send(content)
})
app.get("/ping", cors, (_, res) => {
res.status(200).send("pong")
})
app.get("*", cors, (_, res) => {
res.sendStatus(404)
})
setInterval(() => {
console.log("Updating all countries...")
getAllStuffDone()
}, 1000 * 60 * 60)
// the above setInterval runs the function every hour