Skip to content

Commit

Permalink
Merge pull request #34 from mitsos1os/issue-33-do-not-write-response-…
Browse files Browse the repository at this point in the history
…again

Fix double serving of request
  • Loading branch information
ngfelixl committed Jan 5, 2021
2 parents 9dfa642 + 04c11e5 commit 6f764a7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/server.ts
Expand Up @@ -85,16 +85,18 @@ export class Server {
*/
private createServer(): HttpServer {
return createServer((req, res) => {
this.serveData(req, res);
this.serveWebsite(req, res);
if (!this.serveData(req, res)) {
this.serveWebsite(req, res); // only serve website if request was not served from serveData
}
});
}

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

res.end(JSON.stringify(temporaryPlots));
this.close();
return true; // request successfully server
}
return false; // request not served
}

/**
Expand Down

0 comments on commit 6f764a7

Please sign in to comment.