49 lines
996 B
JavaScript
49 lines
996 B
JavaScript
const express = require("express");
|
|
const cors = require("cors");
|
|
const app = express();
|
|
app.use(cors());
|
|
app.options("*", cors());
|
|
const port = 3000;
|
|
|
|
const getScript = url => {
|
|
return new Promise((resolve, reject) => {
|
|
const http = require("http");
|
|
|
|
let client = http;
|
|
|
|
/*if (url.toString().indexOf("https") === 0) {
|
|
client = https;
|
|
}*/
|
|
|
|
url = "" + url;
|
|
|
|
client
|
|
.get(url, resp => {
|
|
let data = "";
|
|
|
|
// A chunk of data has been recieved.
|
|
resp.on("data", chunk => {
|
|
data += chunk;
|
|
});
|
|
|
|
// The whole response has been received. Print out the result.
|
|
resp.on("end", () => {
|
|
resolve(data);
|
|
});
|
|
})
|
|
.on("error", err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
};
|
|
|
|
app.get("/chillroom-server", (req, res) => {
|
|
(async url => {
|
|
res.json(await getScript(url));
|
|
})(req.query.ip);
|
|
});
|
|
|
|
app.listen(port, () =>
|
|
console.log(`Chillroom server nasluchuje na porcie ${port}!`)
|
|
);
|