Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
@@ -50,16 +50,19 @@ app.use(express.raw({ type: '*/*', limit: '10mb' })); // Untuk menangani buffer
|
|
50 |
|
51 |
app.all('/axios/:method/*', async (req, res) => {
|
52 |
const { method } = req.params;
|
53 |
-
const targetUrl =
|
|
|
|
|
|
|
54 |
|
55 |
try {
|
56 |
const response = await axios({
|
57 |
method: method.toLowerCase(),
|
58 |
-
httpsAgent: agent,
|
59 |
url: targetUrl,
|
60 |
headers: req.headers,
|
61 |
data: req.method === 'POST' ? req.body : undefined, // Hanya kirim data jika metode adalah POST
|
62 |
-
responseType: 'arraybuffer' // Untuk menangani respons sebagai buffer
|
|
|
63 |
});
|
64 |
|
65 |
// Mengambil Content-Type dari header respons
|
@@ -78,8 +81,13 @@ app.all('/axios/:method/*', async (req, res) => {
|
|
78 |
res.send(response.data);
|
79 |
}
|
80 |
} catch (error) {
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
});
|
84 |
}
|
85 |
});
|
|
|
50 |
|
51 |
app.all('/axios/:method/*', async (req, res) => {
|
52 |
const { method } = req.params;
|
53 |
+
const targetUrl = decodeURIComponent(req.params[0]); // Menangani URL setelah /:method/
|
54 |
+
|
55 |
+
console.log(`Method: ${method}`);
|
56 |
+
console.log(`Target URL: ${targetUrl}`);
|
57 |
|
58 |
try {
|
59 |
const response = await axios({
|
60 |
method: method.toLowerCase(),
|
|
|
61 |
url: targetUrl,
|
62 |
headers: req.headers,
|
63 |
data: req.method === 'POST' ? req.body : undefined, // Hanya kirim data jika metode adalah POST
|
64 |
+
responseType: 'arraybuffer', // Untuk menangani respons sebagai buffer
|
65 |
+
httpsAgent: agent // Menonaktifkan validasi SSL jika diperlukan
|
66 |
});
|
67 |
|
68 |
// Mengambil Content-Type dari header respons
|
|
|
81 |
res.send(response.data);
|
82 |
}
|
83 |
} catch (error) {
|
84 |
+
console.error('Error:', error.response ? error.response.data : error.message);
|
85 |
+
|
86 |
+
const statusCode = error.response ? error.response.status : 500;
|
87 |
+
const errorMessage = error.response ? error.response.data : error.message;
|
88 |
+
|
89 |
+
res.status(statusCode).json({
|
90 |
+
error: errorMessage
|
91 |
});
|
92 |
}
|
93 |
});
|