mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2026-04-15 14:48:33 +00:00
api tests
This commit is contained in:
31
NodeServer/routes/app.js
Normal file
31
NodeServer/routes/app.js
Normal file
@@ -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;
|
||||
12
NodeServer/routes/index.js
Normal file
12
NodeServer/routes/index.js
Normal file
@@ -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;
|
||||
28
NodeServer/routes/rtp.js
Normal file
28
NodeServer/routes/rtp.js
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user