-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
62 lines (46 loc) · 1.72 KB
/
server.js
File metadata and controls
62 lines (46 loc) · 1.72 KB
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
import express from 'express'
import cookieParser from 'cookie-parser'
import cors from 'cors'
import path from 'path'
import { fileURLToPath } from 'url'
import { logger } from './services/logger.service.js'
import axios from 'axios'
import { authRoutes } from './api/auth/auth.routes.js'
import { userRoutes } from './api/user/user.routes.js'
import { stationRoutes } from './api/station/station.routes.js'
import { createServer } from 'http'
import { Server } from 'socket.io'
import { setupSocketAPI } from './services/socket.service.js'
const app = express()
const httpServer = createServer(app)
app.use(express.json({ limit: '50mb' }))
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(cors({
origin: true,
credentials: true
}))
app.get('/api/deezer', async (req, res) => {
try {
const { url } = req.query
console.log('Proxying request to Deezer:', url)
if (!url) return res.status(400).send('URL is required')
const response = await axios.get(url)
res.json(response.data)
} catch (err) {
console.error('Error in Deezer proxy route:', err.message)
res.status(500).json({ error: 'Failed to fetch from Deezer', details: err.message })
}
})
app.use('/api/auth', authRoutes)
app.use('/api/user', userRoutes)
app.use('/api/station', stationRoutes)
setupSocketAPI(httpServer)
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
app.use(express.static(path.resolve(__dirname, 'dist')))
app.get('*all', (req, res) => {
res.sendFile(path.resolve(__dirname, 'dist', 'index.html'))
})
const port = process.env.PORT || 3030
httpServer.listen(port, () => logger.info(`Server running on port: ${port}`))