-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (42 loc) · 1.5 KB
/
index.js
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
const express = require('express');
const axios = require('axios');
const cors = require('cors');
const app = express();
require('dotenv').config();
const HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0'
}
app.use(
cors({
origin: '*'
})
)
app.get('/musixmatch/:endpoint([\\/\\w\\.-]*)', async function (req, res) {
try {
const { endpoint } = req.params;
const FULL_URL = `${process.env.MUSIXMATCH_URL}/${endpoint}`;
let params = { ...req.query, apikey: process.env.MUSIXMATCH_API_KEY };
const response = await axios.get(FULL_URL, { params, headers: HEADERS });
const result = response.data;
return res.status(200).json(result);
} catch (error) {
console.error(error);
return res.status(500).json({ message: error.message });
}
});
app.get('/deezer/:endpoint([\\/\\w\\.-]*)', async function (req, res) {
try {
const { endpoint } = req.params;
const FULL_URL = `${process.env.DEEZER_URL}/${endpoint}`;
let params = req.query;
const response = await axios.put(FULL_URL, { params, headers: HEADERS });
const result = response.data;
return res.status(200).json(result);
} catch (error) {
console.error(error);
return res.status(500).json({ message: error.message });
}
});
app.listen(process.env.PORT || 5000, () => {
console.log('proxy running...')
})