deemix-web-frontend/src/index.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-10-23 12:57:36 +02:00
import express from 'express';
import * as dotenv from 'dotenv';
import expressws from 'express-ws';
2021-10-21 20:21:51 +02:00
2021-10-23 12:57:36 +02:00
dotenv.config();
2021-10-19 09:22:31 +02:00
2021-10-23 19:33:00 +02:00
import { logger } from './logger';
import { config } from './config';
import { deezerInstance } from './deemix';
2021-10-20 20:08:41 +02:00
2021-10-23 19:33:00 +02:00
export const port = config.server.port || 4500;
2021-10-20 20:08:41 +02:00
2021-10-23 19:33:00 +02:00
export let searchcache: Record<string, [Album]> = {};
export let albumcache: Record<string, Album> = {};
export let trackcache: Record<string, Track> = {};
2021-10-20 20:08:41 +02:00
2021-10-23 19:33:00 +02:00
export const app = express();
expressws(app);
2021-10-21 20:21:51 +02:00
if (config.server.proxy) {
app.enable('trust proxy');
logger.info('enabled express.js reverse proxy settings');
2021-10-20 20:08:41 +02:00
}
2021-10-21 20:21:51 +02:00
app.use((req, res, next) => {
logger.http(`${(config.server.proxy && req.headers['x-forwarded-for']) || req.connection.remoteAddress} ${req.method} ${req.originalUrl} `);
next();
});
2021-10-19 18:00:54 +02:00
app.use(express.static('public'));
2021-10-19 09:22:31 +02:00
app.use('/data', express.static('data', {extensions: ['flac', 'mp3']}));
2021-10-21 20:21:51 +02:00
2021-10-23 19:33:00 +02:00
import get from './get';
get.forEach((q) => {app.use(q)});
2021-10-19 21:30:55 +02:00
2021-10-23 19:33:00 +02:00
import ws from './ws';
ws.forEach((q) => {app.use(q)});
2021-10-19 21:30:55 +02:00
2021-10-23 12:57:36 +02:00
deezerInstance.login_via_arl(process.env.DEEZER_ARL || '').then(() => {
2021-10-21 20:21:51 +02:00
logger.info('logged into deezer');
2021-10-19 09:22:31 +02:00
app.listen(port, () => {
2021-10-21 20:21:51 +02:00
logger.info(`hosting on http://localhost:${port} and wss://localhost:${port}`);
2021-10-19 09:22:31 +02:00
});
});