mirror of
https://github.com/DeNNiiInc/Website-Stress-Test.git
synced 2026-04-17 12:36:00 +00:00
Fix TypeError in script.js and add static file serving to proxy
This commit is contained in:
@@ -10,6 +10,9 @@ const url = require('url');
|
|||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
const numCPUs = require('os').cpus().length;
|
const numCPUs = require('os').cpus().length;
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
@@ -54,9 +57,9 @@ const getGitInfo = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parts = stdout.trim().split('\n');
|
const parts = stdout.trim().split('\n');
|
||||||
resolve({
|
resolve({
|
||||||
commit: parts[0] || 'Unknown',
|
commit: parts[0] || 'Unknown',
|
||||||
date: parts[1] || 'Unknown'
|
date: parts[1] || 'Unknown'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -114,6 +117,36 @@ if (cluster.isMaster) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Serve static files for the UI
|
||||||
|
if (req.method === 'GET' && (req.url === '/' || req.url === '/index.html' || req.url === '/script.js' || req.url.startsWith('/script.js?') || req.url === '/styles.css' || req.url === '/worker.js')) {
|
||||||
|
let requestPath = req.url.split('?')[0];
|
||||||
|
let filePath = '.' + requestPath;
|
||||||
|
if (requestPath === '/') filePath = './index.html';
|
||||||
|
|
||||||
|
const extname = path.extname(filePath);
|
||||||
|
let contentType = 'text/html';
|
||||||
|
switch (extname) {
|
||||||
|
case '.js': contentType = 'text/javascript'; break;
|
||||||
|
case '.css': contentType = 'text/css'; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.readFile(filePath, (error, content) => {
|
||||||
|
if (error) {
|
||||||
|
if (error.code == 'ENOENT') {
|
||||||
|
res.writeHead(404);
|
||||||
|
res.end('File not found');
|
||||||
|
} else {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end('Error loading file: ' + error.code);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.writeHead(200, { 'Content-Type': contentType });
|
||||||
|
res.end(content, 'utf-8');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Only allow POST requests to the proxy
|
// Only allow POST requests to the proxy
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
res.writeHead(405, { 'Content-Type': 'application/json' });
|
res.writeHead(405, { 'Content-Type': 'application/json' });
|
||||||
|
|||||||
11
script.js
11
script.js
@@ -69,6 +69,7 @@ class StressTestingTool {
|
|||||||
userErrorData: [],
|
userErrorData: [],
|
||||||
errorThreshold: null,
|
errorThreshold: null,
|
||||||
lastUiUpdate: 0,
|
lastUiUpdate: 0,
|
||||||
|
visitedUrls: new Set(),
|
||||||
|
|
||||||
// Enhanced metrics
|
// Enhanced metrics
|
||||||
errorsByCategory: {
|
errorsByCategory: {
|
||||||
@@ -772,11 +773,8 @@ class StressTestingTool {
|
|||||||
this.state.requestHistory = [];
|
this.state.requestHistory = [];
|
||||||
this.state.percentiles = { p50: 0, p95: 0, p99: 0 };
|
this.state.percentiles = { p50: 0, p95: 0, p99: 0 };
|
||||||
|
|
||||||
// Reset crawler
|
// Reset state variables
|
||||||
this.crawler.reset();
|
this.state.visitedUrls.clear();
|
||||||
if (this.config.crawlerEnabled) {
|
|
||||||
this.crawler.urlQueue.push(this.config.targetUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset charts
|
// Reset charts
|
||||||
this.charts.rps.data.labels = [];
|
this.charts.rps.data.labels = [];
|
||||||
@@ -842,6 +840,7 @@ class StressTestingTool {
|
|||||||
this.state.workerStats.set(workerId, message.data);
|
this.state.workerStats.set(workerId, message.data);
|
||||||
this.aggregateStats();
|
this.aggregateStats();
|
||||||
} else if (message.type === 'LOG') {
|
} else if (message.type === 'LOG') {
|
||||||
|
this.state.visitedUrls.add(message.data.url);
|
||||||
this.addToRequestHistory(message.data);
|
this.addToRequestHistory(message.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1217,7 +1216,7 @@ class StressTestingTool {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.config.crawlerEnabled) {
|
if (this.config.crawlerEnabled) {
|
||||||
results["Unique URLs Visited"] = this.crawler.visitedUrls.size;
|
results["Unique URLs Visited"] = this.state.visitedUrls.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|||||||
Reference in New Issue
Block a user