+1
-1
| { | ||
| "name": "rastapi", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "description": "Fast and easy-to-use API maker made for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "rastapi.js", |
+26
-5
@@ -112,9 +112,19 @@ // noinspection JSUnusedGlobalSymbols | ||
| class RastResponse { | ||
| constructor(request, response) { | ||
| constructor(request, response, query, vars) { | ||
| this._request = request; | ||
| this._response = response; | ||
| this._ended = false; | ||
| this._vars = vars; | ||
| this._query = query; | ||
| this.url = request.url; | ||
| } | ||
| getVariables() { | ||
| return this._vars; | ||
| } | ||
| getQuery() { | ||
| return this._query; | ||
| } | ||
| end(string, contentType = "text/json") { | ||
@@ -199,6 +209,17 @@ if (this._ended) return false; | ||
| let vars = {}; | ||
| const dataUrl = urls.find(i => i === req.url) || urls.find(a => { | ||
| const __n = req.url.split("/")[req.url.split("/").length - 1]; | ||
| const _n = __n ? __n.split("?")[0] : null; | ||
| const url = [...req.url.split("/").reverse().slice(1).reverse(), ...(_n ? [_n] : [])].join("/"); | ||
| const _q = req.url.split("/")[req.url.split("/").length - 1].split("?").slice(1).join("?"); | ||
| const query = {}; | ||
| if (_q) { | ||
| _q.split("&").forEach(i => { | ||
| const _i = i.split("="); | ||
| if (_i[0] && _i[1]) query[_i[0]] = _i.slice(1).join("="); | ||
| }); | ||
| } | ||
| const dataUrl = urls.find(i => i === url) || urls.find(a => { | ||
| vars = {}; | ||
| const A = a.split("/").slice(1); | ||
| const B = req.url.split("/").slice(1); | ||
| const B = url.split("/").slice(1); | ||
| if (A.length !== B.length) return false; | ||
@@ -220,3 +241,3 @@ let all = false; | ||
| if (req.method === "GET") { | ||
| const response = new RastResponse(req, res, vars); | ||
| const response = new RastResponse(req, res, query, vars); | ||
| if (this._readers.get(Method.GET).has(dataUrl)) { | ||
@@ -283,3 +304,3 @@ const res = this._readers.get(Method.GET).get(dataUrl); | ||
| /** | ||
| * @param {function} cb | ||
| * @param {function(RastResponse)} cb | ||
| * @param {string?} method | ||
@@ -286,0 +307,0 @@ * @param {string?} url |
+11
-2
@@ -65,7 +65,16 @@ # RastAPI | ||
| $rast.get("/test/:test"); | ||
| server.json((res, vars) => { | ||
| return {"message": "You are in /test/" + vars.test}; | ||
| server.json(res => { | ||
| return {"message": "You are in /test/" + res.getVariables().test}; | ||
| }); | ||
| ``` | ||
| ### Using url query | ||
| ```javascript | ||
| $rast.get("/test"); | ||
| server.json(res => { | ||
| return {"message": "You have successfully entered!", "query": res.getQuery()}; | ||
| }); | ||
| ``` | ||
| ### Not found page | ||
@@ -72,0 +81,0 @@ |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14954
7.43%328
6.15%96
10.34%4
-20%