aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
blob: c0047ad777bf2fb2c1ebab29fa5a86b571440b2b (plain)
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
import { fetchMemberProfile, fetchUser } from './hypixel'
import express from 'express'

const app = express()

app.use((req, res, next) => {
	if (process.env.key && req.headers.key !== process.env.key)
		// if a key is set in process.env and the header doesn't match return an error
		// TODO: make this have a status code
		return res.json({ error: 'Key in header must match key in env' })
	next()
})

app.get('/', async(req, res) => {
	res.json({ ok: true })
})

app.get('/player/:user', async(req, res) => {
	res.json(
		await fetchUser(
			{ user: req.params.user },
			['profiles', 'player']
		)
	)
})

app.get('/player/:user/:profile', async(req, res) => {
	res.json(
		await fetchMemberProfile(req.params.user, req.params.profile)
	)
})

app.listen(8080, () => console.log('App started :)'))