add headers and status to response
This commit is contained in:
parent
f05726bc3f
commit
d9f1839aab
42
index.js
42
index.js
@ -6,6 +6,7 @@ const helmet = require("helmet");
|
|||||||
const morgan = require("morgan");
|
const morgan = require("morgan");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
var package = require("./package.json");
|
var package = require("./package.json");
|
||||||
|
const { request } = require("http");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
@ -56,20 +57,37 @@ function requestPVE (path, method, cookies, callback, body = null, auth = true)
|
|||||||
content.body = prms.toString();
|
content.body = prms.toString();
|
||||||
content.headers.CSRFPreventionToken = cookies.CSRFPreventionToken;
|
content.headers.CSRFPreventionToken = cookies.CSRFPreventionToken;
|
||||||
}
|
}
|
||||||
https.request(content, (res) => {
|
|
||||||
let data = "";
|
const promiseResponse = new Promise((resolve, reject) => {
|
||||||
res.on("data", (d) => {
|
const fullResponse = {
|
||||||
data += d.toString();
|
status: '',
|
||||||
});
|
body: '',
|
||||||
res.on("end", () => {
|
headers: ''
|
||||||
try{
|
};
|
||||||
callback(JSON.parse(data));
|
|
||||||
}
|
const request = https.request(content);
|
||||||
catch (e) {
|
|
||||||
callback(e);
|
request.on('error', reject);
|
||||||
|
request.on('response', response => {
|
||||||
|
response.setEncoding('utf8');
|
||||||
|
fullResponse.status = response.statusCode;
|
||||||
|
fullResponse.headers = response.headers;
|
||||||
|
response.on('data', chunk => { fullResponse.body += chunk; });
|
||||||
|
response.on('end', () => {
|
||||||
|
if(fullResponse.body){
|
||||||
|
fullResponse.body = JSON.parse(fullResponse.body);
|
||||||
}
|
}
|
||||||
|
resolve(fullResponse);
|
||||||
});
|
});
|
||||||
}).on("error", (e) => {callback(e)}).end();
|
});
|
||||||
|
|
||||||
|
request.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
promiseResponse.then(
|
||||||
|
response => {callback(response);},
|
||||||
|
error => {callback(error);}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.listen(80, () => {
|
app.listen(80, () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user