diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-07 20:15:23 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-07 20:15:23 +0200 |
commit | c90ebfa1c84e1ba668a65d0325e96d201c4abbf8 (patch) | |
tree | 3a4e80dc0461ad1c6e0c763aad669d39a458ebe3 /core/request.js | |
parent | 981b80066504cf94224f0fd431281edb740f2669 (diff) | |
download | electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.tar.gz electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.tar.bz2 electrode-c90ebfa1c84e1ba668a65d0325e96d201c4abbf8.zip |
Electrode is stable!
Diffstat (limited to 'core/request.js')
-rw-r--r-- | core/request.js | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/core/request.js b/core/request.js index caceceb..e9d76b1 100644 --- a/core/request.js +++ b/core/request.js @@ -1,10 +1,11 @@ const chalk = require('chalk'); -const mime = require('mime'); -const FileType = require('file-type'); +const mime = require('mime-types'); +const path = require('path'); module.exports = (req, res, post, files) => { try { res.setHeader("X-Electrode-WorkerID", cluster.worker.id) + res.setHeader("Server", "Electrode/" + version + " (" + require('os').type() + ")") res.setHeader('Cache-Control', 'private, no-cache, no-store, must-revalidate'); res.setHeader('Expires', '-1'); res.setHeader('Pragma', 'no-cache'); @@ -12,7 +13,7 @@ module.exports = (req, res, post, files) => { console.log(chalk.gray(cluster.worker.id + " ") + chalk.blue("warn:") + " working around exploit"); res.writeHead(301, { 'Location': '/index.php' }); res.end(); - } else if (req.url.trim() == '/' || req.url.trim() == '//' || req.url.trim() == '') { + } else if (req.url.trim() == '/' || req.url.trim() == '//' || req.url.trim() == '') { console.log(chalk.gray(cluster.worker.id + " ") + chalk.blue("warn:") + " working around redirection trap"); res.writeHead(301, { 'Location': '/index.php' }); res.end(); @@ -42,10 +43,16 @@ module.exports = (req, res, post, files) => { res.end(); console.log(chalk.gray(cluster.worker.id + " ") + chalk.red("error:") + " while loading file: " + error.message); } else { - FileType.fromFile(filename).then((type) => { - res.writeHead(200, { 'Content-Type': type + "", 'Content-Size': file.toString().length }); - res.end(file); - }); + ext = path.extname(filename); + if (ext === ".css") { + mimet = "text/css" + } else if (ext === ".js") { + mimet = "application/javascript" + } else { + mimet = mime.contentType(ext); + } + res.writeHead(200, { 'Content-Type': mimet, 'Content-Size': file.toString().length }); + res.end(file); } }) } else { @@ -88,7 +95,6 @@ module.exports = (req, res, post, files) => { console.log(phpc.error.stack); res.write('<html><head><title>' + phpc.error.name + ' - PHP error</title></head><body><h1>' + phpc.error.name + '</h1><p>The PHP integration didn\'t fulfill the request correctly:</p><pre>' + phpc.stderr + '</pre><pre>' + phpc.error.message.split("\n").join("<br>") + '</pre><hr><address>' + config.product.name + ' version ' + version + '</address></body></html>'); res.end(); - core.headClean(); } }); } |