mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-11-28 08:44:07 +00:00
Compare commits
3
Commits
v3.6.16
...
node-server
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21fa0f9293 | ||
|
|
93666bb991 | ||
|
|
39708dddc4 |
No files matched your search
@@ -7,7 +7,7 @@
|
|||||||
<groupId>me.SuperRonanCraft</groupId>
|
<groupId>me.SuperRonanCraft</groupId>
|
||||||
<artifactId>BetterRTPAddons</artifactId>
|
<artifactId>BetterRTPAddons</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.8.8</version>
|
<version>1.8.9</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
@@ -52,6 +52,7 @@
|
|||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<!-- Builds to local storage 3 folders back from where its saved, it's for Ronan :D -->
|
||||||
<outputDirectory>../../../Java/plugins</outputDirectory>
|
<outputDirectory>../../../Java/plugins</outputDirectory>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
Whitespace-only changes.
Generated
+4455
File diff suppressed because it is too large.
Load diff
@@ -4,9 +4,16 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.19.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^29.7.0",
|
||||||
|
"supertest": "^6.3.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>BetterRTP - Routes</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>BetterRTP API Routes coming soon!</p>
|
||||||
|
</body>
|
||||||
|
<script src="index.js"></script>
|
||||||
|
</html>
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>BetterRTP - API</title>
|
<title>BetterRTP - API</title>
|
||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body>
|
||||||
|
<p>BetterRTP API coming soon!</p>
|
||||||
|
</body>
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
const api = require("./index.js");
|
||||||
|
|
||||||
|
//Middleware
|
||||||
|
//Allows to send json body
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// app.use((req, red, next) => {
|
||||||
|
// const yellow = "\x1b[33m%s\x1b[0m";
|
||||||
|
|
||||||
|
// // Log out the request type and resource
|
||||||
|
// console.log(yellow, `${req.method} request to ${req.path}`);
|
||||||
|
// next();
|
||||||
|
// });
|
||||||
|
|
||||||
|
app.use(express.static("public"));
|
||||||
|
|
||||||
|
//Routes
|
||||||
|
//Send all requests starting with /api to index.js to routes folder
|
||||||
|
app.use("/api", api);
|
||||||
|
|
||||||
|
//https://localhost route to default page
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
res.sendFile(path.join(__dirname, "/public/index.html"));
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = app;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
const router = require("express").Router();
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const rtp = require("./rtp");
|
||||||
|
|
||||||
|
router.use("/rtp", rtp);
|
||||||
|
|
||||||
|
router.get("/", (req, res) => {
|
||||||
|
res.sendFile(path(__dirname, "../public/api/index.html"));
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
const rtpdata = require("express").Router();
|
||||||
|
|
||||||
|
rtpdata.post("/", (req, res) => {
|
||||||
|
const validate = () =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const json = req.body;
|
||||||
|
if (json !== undefined) {
|
||||||
|
resolve(json);
|
||||||
|
} else {
|
||||||
|
reject(new Error("No Json"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
validate()
|
||||||
|
.then((data) => {
|
||||||
|
console.log("Validate:", data);
|
||||||
|
res.json({
|
||||||
|
added: true,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log("Error:", err);
|
||||||
|
res.json({
|
||||||
|
added: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = rtpdata;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const app = require("./routes/app.js");
|
||||||
|
const port = 3001;
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`BetterRTP Server online at http://localhost:${port}`);
|
||||||
|
});
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const request = require("supertest");
|
||||||
|
const app = require("../routes/app.js");
|
||||||
|
|
||||||
|
describe("GET /api", () => {
|
||||||
|
it("responds with html file", async () => {
|
||||||
|
const res = await request(app).get("/api");
|
||||||
|
// console.log(res.header);
|
||||||
|
expect(res.header["content-type"]).toBe("text/html; charset=UTF-8");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("POST /api/rtp", () => {
|
||||||
|
it("responds with json and `added = false`", async () => {
|
||||||
|
const res = await request(app).post("/api/rtp");
|
||||||
|
expect(res.header["content-type"]).toBe("application/json; charset=utf-8");
|
||||||
|
expect(res.body.added).toBe(false);
|
||||||
|
});
|
||||||
|
it("responds with json and `added = true`", async () => {
|
||||||
|
const res = await request(app).post("/api/rtp").send({
|
||||||
|
playerId: "test123",
|
||||||
|
});
|
||||||
|
expect(res.header["content-type"]).toBe("application/json; charset=utf-8");
|
||||||
|
expect(res.body.added).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user