1
0
Fork 0
mirror of https://github.com/sbrl/powahroot.git synced 2024-09-19 19:55:57 +00:00

RouterContext: add conveience getter querystring

This commit is contained in:
Starbeamrainbowlabs 2024-06-05 12:44:59 +01:00
parent 46c8d33ff1
commit 758eb6d052
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 18 additions and 0 deletions

View file

@ -15,6 +15,10 @@ npm install --save powahroot
----- -----
## v1.2.8
- Add convenience getter `RequestContext.querystring`
## v1.2.7 ## v1.2.7
- Update dependencies to fix security issues - Update dependencies to fix security issues

View file

@ -1,6 +1,7 @@
"use strict"; "use strict";
import url from 'url'; import url from 'url';
import querystring from 'querystring';
import Sender from './Sender.mjs'; import Sender from './Sender.mjs';
import RequestEnvironment from './RequestEnvironment.mjs'; import RequestEnvironment from './RequestEnvironment.mjs';
@ -9,6 +10,19 @@ import RequestEnvironment from './RequestEnvironment.mjs';
* Contains context information about a single request / response pair. * Contains context information about a single request / response pair.
*/ */
class RouterContext { class RouterContext {
/**
* Returns the parsed querystring from the request url, or an empty object if no query string was found.
*
* NOTE FROM THE NODE.JS DOCS: The object returned by the querystring.parse() method [used in this getter] does not prototypically inherit from the JavaScript Object. This means that typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.
*
* @return {Object} The parsed query string as an object, or an empty object.
*/
get querystring() {
const qs = this.url.querystring;
if(qs.query == null) return {};
return querystring.parse(qs);
}
constructor(in_request, in_response) { constructor(in_request, in_response) {
/** /**
* The Node.JS request object * The Node.JS request object