My repl maxes out CPU and Memory after a few seconds, I have no idea why. The only file I’ve changed is src/server.js The code I changed is shown below:
https://replit.com/@CameronDick1/pixelbulb-beta
let cache = {};
const cacheList = ['ph', 'wp-content/uploads/ph.svg', 'bh', 'bh-2', 'kh', 'wh', 'edit-webpage', 'edit-webpage-2', 'minion-6-beta', 'cmg', 'wu']
function updatePH() {
for(let url of cacheList){
fetch('https://pixelbulb.online/' + url).then(async (e) => {
const up = await e;
const bu = await up.arrayBuffer();
if (!cache[url] || bu != cache[url].content) {
if (cache !== {}) {
const n = setInterval(() => {
updatePH()
}, 7000)
setTimeout(() => { clearInterval(n) }, 1000000)
}
cache[url] = {content: bu, contentType: up.headers.get('Content-Type') || 'application/octet-stream'};
}
}).catch(e => console.log(e))
}
return;
}
setInterval(() => {
updatePH()
}, 30000)
updatePH();
app.get('/*', async (req, res, next) => {
const u = new URL(req.originalUrl, 'https://pixelbulb.online');
const path = req.originalUrl == '/' ? 'ph' : (u.pathname.substring(1, u.pathname.endsWith('/') ? u.pathname.length-1 : undefined));
console.log(path);
if(!cache[path]) {res.send('no data'); return};
try {
res.setHeader('Content-Type', cache[path].contentType.split(';')[0]);
res.send(Buffer.from(cache[path].content));
} catch (e) { console.log(e); res.send(`<script>alert('Something went wrong, you\'ll be redirected to Pixelbulb');location.replace('https://pixelbulb.online/ph')</script>`); }
})