-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (36 loc) · 1.3 KB
/
app.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
const express = require('express')
const app = express()
const port = 3000
require('dotenv').config()
const ads = require('./data/ads.json')
const mcVersions = require('./data/versions.json')
app.get('/ads', function (req, res) {
if(!req.query.url) return res.status(404).json({ success: false, reason: "NO_DOMAIN_SPECIFIED"})
let advertiser = ads.sites[req.query.url.toLowerCase()]?.advertiser
if(!advertiser) return res.status(404).json({ success: false, reason: "NO_ADVERTISER_FOUND"})
return res.json(advertiser)
})
app.get('/v1/mc/versions', function (req, res) {
let versionData = {
success: true,
versions: mcVersions
}
if(req.query.version) {
let filteredVersions = mcVersions.filter(version => version.version_name === req.query.version)
if(filteredVersions.length > 0) {
versionData.version = filteredVersions[0]
delete versionData['versions']
} else {
versionData.success = false
versionData.error = "INVALID_VERSION"
versionData.versions = mcVersions.map(version => version.version_name)
}
}
if(!versionData.success) {
res.status(404)
}
return res.json(versionData)
})
app.listen(port, () => {
console.log(`Listening on http://localhost:${port}`)
})