apollo/app.js
2024-12-06 07:07:19 +00:00

42 lines
1.3 KiB
JavaScript

const config = require("./config/configuration");
const express = require('express');
const helmet = require("helmet");
const logger = require("./services/logging");
const rateLimit = require("express-rate-limit");
const sessions = require("./services/session-manager");
const PlexTracker = require("./services/trackers/plex-tracker");
const SpotifyTracker = require("./services/trackers/spotify-tracker");
const Recorder = require("./services/recorder");
const MalojaScrobbler = require("./services/scrobblers/maloja-scrobbler");
const maloja = new MalojaScrobbler(config.maloja, logger);
const spotify = new SpotifyTracker(config.spotify);
(async () => await spotify.loadCredentials())();
const plex = new PlexTracker(config.plex);
const recorder = new Recorder(sessions, [plex, spotify], [maloja], config.scrobble, logger);
setInterval(() => recorder.record(), 5000);
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);
const PORT = config.web.port || 9011;
app.listen(PORT, () => {
logger.info("Listening to port " + PORT + ".");
});