Skip to content

Commit

Permalink
properly parse request body using express.json()
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexInABox committed Aug 12, 2024
1 parent a2c6213 commit 4a9a1a2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/DataTransmitServer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from "express";
const app = express()
app.use(express.json()) // for parsing application/json
const port = 80

import { promises as fs } from 'fs';
Expand All @@ -16,10 +17,20 @@ async function writeServerStats() {

async function initalize() {
app.post("/", async (req, res) => {
console.log(req.body);
if (typeof req.body.PacketName !== 'string') {
return res.sendStatus(400); // https://http.cat/400
if (req.body === undefined) {
console.log("req.body is undefined");
return res.sendStatus(400);
}
if (req.body.PacketName === undefined) {
console.log("req.body.PacketName is undefined");
return res.sendStatus(400);
}
if (typeof req.body.PacketName !== "string") {
console.log("req.body.PacketName is not a string");
return res.sendStatus(400);
}

console.log("Received packet: " + req.body.PacketName);

const body = req.body;

Expand Down

0 comments on commit 4a9a1a2

Please sign in to comment.