Revolution/modules/request_handler.js
2019-08-17 23:33:00 +01:00

25 lines
No EOL
1 KiB
JavaScript

const fs = require("fs");
module.exports = {
handle:function(modules, internals, emoji, req, res) {
/*
req - Request from client
res - Response from server
*/
res.set("Server-Type", "Revolution");
if (req.url == "/") {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested`);
res.end(); // Send a blank response, this can be changed to make it do whatever.
} else {
fs.access(__dirname + req.url, fs.constants.F_OK | fs.constants.W_OK, (err) => {
if (err) {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested - Returned 404`);
res.status(404).send("404!<hr>Revolution");
} else {
modules.logger.log(`${internals.types.b}: ${req.method}`, emoji.page, `${req.url} was requested`);
res.sendFile(__dirname + req.url);
}
});
}
}
}