Skip to content

Commit

Permalink
feat(webserver): Streamed compression of some heavy requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed May 30, 2021
1 parent 98b2757 commit 0d7d836
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions backend/lib/webserver/RobotRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { Hub, sseHub } = require("expresse");
const ValetudoRobot = require("../core/ValetudoRobot");

const CapabilitiesRouter = require("./CapabilitiesRouter");
const {stringifyAndGZip} = require("../utils/streamHelpers");

class RobotRouter {
/**
Expand Down Expand Up @@ -36,7 +37,14 @@ class RobotRouter {
try {
const polledState = await this.robot.pollState();

res.json(polledState);
stringifyAndGZip(polledState).then(data => {
res.header("Content-Type", "application/json; charset=utf-8");
res.header("Content-Encoding", "gzip");

res.send(data);
}).catch(err => {
throw err;
});
} catch (err) {
res.status(500).send(err.toString());
}
Expand All @@ -56,7 +64,14 @@ class RobotRouter {
try {
const polledState = await this.robot.pollState();

res.json(polledState.map);
stringifyAndGZip(polledState.map).then(data => {
res.header("Content-Type", "application/json; charset=utf-8");
res.header("Content-Encoding", "gzip");

res.send(data);
}).catch(err => {
throw err;
});
} catch (err) {
res.status(500).send(err.toString());
}
Expand Down

0 comments on commit 0d7d836

Please sign in to comment.