Add parser API

This commit is contained in:
buzzcode2007 2025-03-20 02:01:19 +00:00
parent 1d2e0726da
commit 6236669e4b

39
scripts/ParserAPI.js Normal file
View file

@ -0,0 +1,39 @@
const Messaging = require('./messaging').Messaging;
const RequestParser = require(`./RequestParser`).RequestParser;
class ParserAPI {
/*
Custom paths used for the API.
*/
#paths = {
"parser": "/whoami"
}
/*
Create the header parser API.
@param {Express} INSTANCE - The Express instance
*/
constructor(INSTANCE) {
this[`instance`] = INSTANCE;
this.receive();
}
/*
Receive requests.
*/
receive() {
[`get`, `post`].forEach((METHOD) => {
this[`instance`][METHOD](`/api${this.#paths["parser"]}`, (REQUEST, RESPONSE) => {
try {
let PARSER = new RequestParser(REQUEST);
RESPONSE.json(PARSER.getHeaders());
} catch(ERROR) {Messaging.exception(RESPONSE, ERROR)}
})
})
}
}
module.exports = {ParserAPI}