-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
35 lines (29 loc) · 994 Bytes
/
proxy.js
File metadata and controls
35 lines (29 loc) · 994 Bytes
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
// proxy.js
const express = require('express');
const cors = require('cors');
const fetch = require('node-fetch');
const app = express();
const PORT = 3001;
app.use(cors());
app.use(express.json());
app.post('/leetcode', async (req, res) => {
const { query, variables } = req.body;
try {
const response = await fetch('https://leetcode.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// Optional: You can also add cookies or headers here if needed
},
body: JSON.stringify({ query, variables })
});
const data = await response.json();
res.status(response.status).json(data);
} catch (err) {
console.error('Error fetching from LeetCode:', err.message);
res.status(500).json({ error: 'Something went wrong' });
}
});
app.listen(PORT, () => {
console.log(`✅ CORS Proxy running at http://localhost:${PORT}`);
});