Skip to content

Commit 6f764a7

Browse files
authored
Merge pull request #34 from mitsos1os/issue-33-do-not-write-response-again
Fix double serving of request
2 parents 9dfa642 + 04c11e5 commit 6f764a7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ export class Server {
8585
*/
8686
private createServer(): HttpServer {
8787
return createServer((req, res) => {
88-
this.serveData(req, res);
89-
this.serveWebsite(req, res);
88+
if (!this.serveData(req, res)) {
89+
this.serveWebsite(req, res); // only serve website if request was not served from serveData
90+
}
9091
});
9192
}
9293

9394
/**
9495
* Serves the plot data at /data/:id of the container[id].
9596
* It markes the container as opened and not pending anymore.
9697
* @param req
97-
* @param res
98+
* @param res
99+
* @returns {boolean} - Whether the request was served or not
98100
*/
99101
private serveData(req: IncomingMessage, res: ServerResponse) {
100102
if (req && req.url && req.url.match(/data\/[0-9]+/)) {
@@ -109,7 +111,9 @@ export class Server {
109111

110112
res.end(JSON.stringify(temporaryPlots));
111113
this.close();
114+
return true; // request successfully server
112115
}
116+
return false; // request not served
113117
}
114118

115119
/**

0 commit comments

Comments
 (0)