2024-12-03 18:58:15 -05:00
|
|
|
const config = require("./config/configuration");
|
2024-12-03 17:46:43 -05:00
|
|
|
const express = require('express');
|
|
|
|
const helmet = require("helmet");
|
|
|
|
const logger = require("./services/logging");
|
2024-12-03 18:58:15 -05:00
|
|
|
const rateLimit = require("express-rate-limit");
|
2024-12-05 03:36:22 -05:00
|
|
|
const sessions = require("./services/session-manager");
|
2024-12-05 10:15:56 -05:00
|
|
|
const PlexTracker = require("./services/trackers/plex-tracker");
|
|
|
|
const SpotifyTracker = require("./services/trackers/spotify-tracker");
|
2024-12-05 03:36:22 -05:00
|
|
|
const Recorder = require("./services/recorder");
|
2024-12-05 12:32:37 -05:00
|
|
|
const MalojaScrobbler = require("./services/scrobblers/maloja-scrobbler");
|
2024-12-03 17:46:43 -05:00
|
|
|
|
|
|
|
|
2024-12-06 13:19:49 -05:00
|
|
|
let trackers = []
|
|
|
|
trackers = trackers.concat(config.spotify.map(config => new SpotifyTracker(config)));
|
|
|
|
trackers = trackers.concat(config.plex.map(config => new PlexTracker(config)));
|
|
|
|
|
|
|
|
const uniqueSpotifys = new Set(config.spotify.map(c => c.client_id));
|
|
|
|
for (let spotify of uniqueSpotifys)
|
|
|
|
(async () => await spotify.loadCredentials())();
|
|
|
|
|
|
|
|
const scrobblers = config.maloja.map(config => new MalojaScrobbler(config, logger));
|
|
|
|
const recorder = new Recorder(sessions, trackers, scrobblers, config.scrobble, logger);
|
2024-12-05 03:36:22 -05:00
|
|
|
|
|
|
|
setInterval(() => recorder.record(), 5000);
|
2024-12-03 17:46:43 -05:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
app.use(express.json());
|
|
|
|
app.use("/", require("./routes/home"));
|
|
|
|
app.use("/api", require("./routes/api"));
|
|
|
|
|
|
|
|
const limiter = rateLimit({
|
|
|
|
legacyHeaders: true,
|
|
|
|
standardHeaders: true,
|
|
|
|
windowMs: 15 * 60 * 1000,
|
|
|
|
limit: 50,
|
|
|
|
max: 2,
|
|
|
|
message: "Too many requests; please try again later.",
|
|
|
|
keyGenerator: (req) => req.ip,
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use(helmet());
|
|
|
|
app.use(limiter);
|
|
|
|
|
2024-12-06 01:57:10 -05:00
|
|
|
const PORT = config.web.port || 9011;
|
2024-12-03 17:46:43 -05:00
|
|
|
app.listen(PORT, () => {
|
|
|
|
logger.info("Listening to port " + PORT + ".");
|
|
|
|
});
|