forked from breatheco-de/update-script-cron-task-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (50 loc) · 1.52 KB
/
server.js
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
const express = require("express");
const app = express();
const cors = require("cors");
//const formidable = require("express-formidable");
const fs = require("fs");
const filename = "data.json";
require("dotenv").config();
app.use(cors());
//app.use(formidable());
app.use(express.json());
//app.use(express.urlencoded({ extended: true }));
const backendUrl = `https://${process.env.CODESPACE_NAME}-${process.env.HOST_PORT}.app.github.dev`;
app.use("/public", express.static("./public"));
app.get("/", (req, res) => {
console.log("Testing VMInfo");
if (fs.existsSync(filename)) {
const jsonData = fs.readFileSync(filename, "utf8");
res.send(`
<h1>${backendUrl}</h1>
<code>${jsonData}</code>
`);
} else {
res.status(404).send(`
<h1>${backendUrl}</h1>
<hr
<h3>Ready to send the validation data</h3>
<h3>Listo para enviar la información de validación</h3>
`);
}
});
app.post("/", async (req, res) => {
console.log("Receiving data");
let data=req.body
fs.writeFileSync("script.sh", atob(data.scriptText), "utf8");
delete data.scriptText
fs.writeFileSync(filename, JSON.stringify(data), "utf8");
res.status(200).send({ message: "JSON saved successfully" });
});
app.listen(process.env.HOST_PORT, () => {
let text = `
/* Your url is:
* -----------------------------------
* ${backendUrl}
* -----------------------------------
*/
console.log(${backendUrl})
`;
//console.clear();
console.log("Your URL for the verification script is: " + backendUrl);
});