Skip to content

Commit

Permalink
Significantly refactored all the codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Gokan committed Sep 18, 2020
1 parent fe90dd1 commit fe52b4e
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 137 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
npm-debug.log
.idea
.idea/
.idea/
*.swp
27 changes: 13 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
const express = require('express');
const app = express();
var bodyParser = require('body-parser')
let workloads = require("./workloads");

const getDurationInMilliseconds = (start) => {
const NS_PER_SEC = 1e9;
const NS_TO_MS = 1e6;
const diff = process.hrtime(start);

return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
}

app.use(bodyParser.json({limit: '10000mb'}))
const bodyParser = require('body-parser');
let workloads = require("./workloads/workloads");
const helper = require("./workloads/helper");

app.use(bodyParser.json({limit: '10000mb'}));
app.use('/images', express.static('images'));
app.use((req, res, next) => {
const start = process.hrtime();
console.log(`Received ${req.method} ${req.originalUrl} from ${req.headers['referer']} [RECEIVED]`)

res.on('close', () => {
const durationInMilliseconds = getDurationInMilliseconds(start);
const durationInMilliseconds = helper.getDurationInMilliseconds(start);
console.log(`Closed received ${req.method} ${req.originalUrl} from ${req.headers['referer']} [CLOSED] ${durationInMilliseconds.toLocaleString()} ms`)
});
next();
Expand Down Expand Up @@ -77,6 +70,12 @@ app.get('*/x/:sendToNext?/:isPromised?', (req, res) => {
}
});

app.get('*/', (req, res) => res.send("Hi :)!<br />Please use one of the following endpoints:<br />* /cpu for CPU intensive workloads<br />* /mem for memory intensive workloads<br />* /disk for disk intensive workloads<br />* /net for network intensive workloads<br />* /x for combined workloads"));
app.get('*/', (req, res) => {
const showdown = require('showdown');
const fs = require('fs');
const converter = new showdown.Converter();
const text = fs.readFileSync('./README.md', 'utf8');
res.send(converter.makeHtml(text));
});

app.listen(30005, "0.0.0.0");
192 changes: 192 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"form-data": "^3.0.0",
"fs": "0.0.1-security",
"malloc": "latest",
"showdown": "^1.9.1",
"sync-request": "^6.1.0",
"url": "^0.11.0",
"url-to-options": "^2.0.0"
Expand Down
Loading

0 comments on commit fe52b4e

Please sign in to comment.