diff --git a/scripts/ParserAPI.js b/scripts/ParserAPI.js new file mode 100644 index 0000000..65dce05 --- /dev/null +++ b/scripts/ParserAPI.js @@ -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} \ No newline at end of file