-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (33 loc) · 1.07 KB
/
index.js
File metadata and controls
43 lines (33 loc) · 1.07 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
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const cors = require('cors');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, './build')));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));
});
app.post('/send', async (req, res) => {
const { method, url, headers, body, token } = req.body;
try {
const config = {
method,
url,
headers: {
...headers,
Authorization: `Bearer ${token}` // Add Bearer token to the request headers
},
data: body
};
const response = await axios(config);
res.json(response.data);
} catch (error) {
res.status(500).json({ error: 'An error occurred' });
}
});
const port = process.env.PORT || 8000; // or any other port number you prefer
app.listen(port);