-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
69 lines (59 loc) · 1.72 KB
/
Copy pathapp.js
File metadata and controls
69 lines (59 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
63
64
65
66
67
68
69
const express = require("express");
const axios = require("axios");
const cors = require("cors");
const app = express();
const PORT = process.env.PORT || 3005;
require("dotenv").config();
app.options("*", cors());
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
const TOKEN = process.argv[2];
app.get(`${process.env.ENDPOINT}`, cors(), async (req, res) => {
console.log("🕵️♂️ Proxying Request 🔄 : ", req.url);
const config = {
method: "get",
url: `${process.env.SERVER_URL}${req.url}`,
headers: {
// Authorization: req.headers["authorization"],
Authorization: `Bearer ${TOKEN}`,
Origin: process.env.ORIGIN,
Scope: "employee",
},
};
axios(config)
.then(async function (response) {
console.log("✅ RESPONSE");
await response;
console.log(response.data);
res.json(response.data);
})
.catch(function (error) {
console.log("IN ERROR", error);
res.status(500).json({ error: error });
});
});
app.get(`/download`, cors(), async (req, res) => {
console.log("🕵️♂️ Proxying Download Request 🔄 : ", req.url);
var config = {
method: "get",
url: `${process.env.SERVER_URL}${req.url}`,
headers: {
Authorization: req.headers["authorization"],
Origin: process.env.ORIGIN,
Scope: "user",
},
};
axios(config)
.then(async function (response) {
console.log("✅ RESPONSE");
await response;
console.log(response.data);
res.json(response.data);
})
.catch(function (error) {
console.log("IN ERROR", error);
res.status(500).json({ error: error });
});
});
app.listen(PORT, () => {
console.log(`📊 Proxy Server is running on port ${PORT}`);
});