forked from Altpapier/SkyHelperAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (56 loc) · 2.25 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
//CREDIT: https://github.com/Senither/hypixel-skyblock-facade (Modified)
const FetchurRoute = require('./routes/v1/fetchur');
const ProfileRoute = require('./routes/v1/profile');
const ProfilesRoute = require('./routes/v1/profiles');
const ProfileItemsRoute = require('./routes/v1/profileItems');
const ProfilesItemsRoute = require('./routes/v1/profilesItems');
const ProfileV2Route = require('./routes/v2/profile');
const ProfilesV2Route = require('./routes/v2/profiles');
const NetworthRoute = require('./routes/v2/networth');
const ItemNetworthRoute = require('./routes/v2/itemNetworth');
const NotFound = require('./middleware/notfound');
const Auth = require('./middleware/auth');
const ErrorHandler = require('./middleware/errorhandler');
const rateLimit = require('express-rate-limit');
const express = require('express');
const app = express();
const refreshCollections = require('./data/refreshCollections');
const { refreshPrices } = require('./data/refreshPrices');
const checkForUpdate = require('./middleware/checkforupdate');
require('dotenv').config();
const port = process.env.PORT || 3000;
process.on('uncaughtException', (error) => console.log(error));
process.on('unhandledRejection', (error) => console.log(error));
const limiter = rateLimit({
windowMs: 1000 * 60, // 1 minute
max: 60,
standardHeaders: true,
legacyHeaders: false,
message: {
status: 429,
message: 'Too many requests, please try again later.',
},
});
app.use(express.static(__dirname + '/public'));
app.use(limiter);
app.use(Auth);
app.use(require('cors')());
app.use(express.json({ limit: '15mb' }));
app.use(express.urlencoded({ extended: true }));
app.get('/v1/fetchur', FetchurRoute);
app.get('/v1/profile/:uuid/:profileid', ProfileRoute);
app.get('/v1/profiles/:uuid', ProfilesRoute);
app.get('/v1/items/:uuid/:profileid', ProfileItemsRoute);
app.get('/v1/items/:uuid', ProfilesItemsRoute);
app.get('/v2/profile/:uuid/:profileid', ProfileV2Route);
app.get('/v2/profiles/:uuid', ProfilesV2Route);
app.post('/v2/networth', NetworthRoute);
app.post('/v2/networth/item', ItemNetworthRoute);
app.use(NotFound);
app.use(ErrorHandler);
refreshCollections();
refreshPrices();
checkForUpdate();
app.listen(port, () => {
console.log(`Now listening on port ${port}`);
});