Initial CarPlay audio server implementation with file management, playlists, and album/single classification
This commit is contained in:
42
src/server.js
Normal file
42
src/server.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import tracksRouter from './routes/tracks.js';
|
||||
import playlistsRouter from './routes/playlists.js';
|
||||
import albumsRouter from './routes/albums.js';
|
||||
import uploadRouter from './routes/upload.js';
|
||||
import { initDatabase } from './database/db.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Initialize database
|
||||
await initDatabase();
|
||||
|
||||
// Routes
|
||||
app.use('/api/tracks', tracksRouter);
|
||||
app.use('/api/playlists', playlistsRouter);
|
||||
app.use('/api/albums', albumsRouter);
|
||||
app.use('/api/upload', uploadRouter);
|
||||
|
||||
// Serve audio files
|
||||
app.use('/audio', express.static(path.join(process.cwd(), 'audio_library')));
|
||||
app.use('/artwork', express.static(path.join(process.cwd(), 'artwork')));
|
||||
|
||||
// Health check
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok', message: 'CarPlay Audio Server is running' });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🎵 CarPlay Audio Server running on port ${PORT}`);
|
||||
console.log(`📁 Audio library: ${path.join(process.cwd(), 'audio_library')}`);
|
||||
});
|
||||
Reference in New Issue
Block a user