New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rastapi

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rastapi - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+1
-1
package.json
{
"name": "rastapi",
"version": "0.0.1",
"version": "0.0.2",
"description": "Fast and easy-to-use API maker made for JavaScript",

@@ -5,0 +5,0 @@ "main": "rastapi.js",

@@ -116,2 +116,3 @@ // noinspection JSUnusedGlobalSymbols

this._ended = false;
this.url = request.url;
}

@@ -151,21 +152,50 @@

this._server = (http ? require("http") : require("https")).createServer((req, res) => {
if (req.method === "GET") {
const response = new RastResponse(req, res);
if (this._readers.has(Method.GET) && this._readers.get(Method.GET).has(req.url)) {
const res = this._readers.get(Method.GET).get(req.url);
const cb = res.cb(response);
if (cb === undefined) return;
if (res.type === "file") response.file(cb);
else response.end(JSON.stringify(typeof cb === "object" ? cb : {error: "Invalid response"}));
if (!this._readers.has(req.method)) return;
if (req.url === "/favicon.ico") return;
const urls = Array.from(this._readers.get(req.method)).map(i => i[0]);
let vars = {};
const dataUrl = urls.find(i => i === req.url) || urls.find(a => {
vars = {};
const A = a.split("/").slice(1);
const B = req.url.split("/").slice(1);
if (A.length !== B.length) return false;
let all = false;
for (let i = 0; i < A.length; i++) {
if (A[i] === "*") {
all = true;
continue;
}
if (A[i].startsWith(":")) {
vars[A[i].split("").slice(1).join("")] = B[i];
continue;
}
if (A[i] !== B[i] && !all) return false;
}
return true;
});
if (req.method === "GET") {
const response = new RastResponse(req, res, vars);
if (this._readers.get(Method.GET).has(dataUrl)) {
const res = this._readers.get(Method.GET).get(dataUrl);
const cb = res.cb(response, vars);
if (cb === undefined) return;
if (res.type === "file") response.file(cb);
else response.end(JSON.stringify(typeof cb === "object" ? cb : {error: "Invalid response"}));
} else {
if (this._readers.has("404")) {
response.end(JSON.stringify(this._readers.get("404").get("*").cb(response)));
}
}
} else if (req.method === "POST") {
return; // TODO
let body = "";
req.on("data", c => body += c);
req.on("end", () => {
res.writeHead(StatusCodes.OK, {"Content-Type": "text/json"});
res.end(body);
});
}
} else if (req.method === "POST") {
return; // TODO
let body = "";
req.on("data", c => body += c);
req.on("end", () => {
res.writeHead(StatusCodes.OK, {"Content-Type": "text/json"});
res.end(body);
});
}
});
)
;
}

@@ -211,3 +241,4 @@

class RastServerHTTP extends RastServer {
class RastServerHTTP
extends RastServer {
constructor() {

@@ -232,2 +263,6 @@ super();

static notFound() {
mode = {method: "404", url: "*"};
}
static VERSION = "0.0.1";

@@ -234,0 +269,0 @@

@@ -59,2 +59,21 @@ # RastAPI

server.file(() => "./myfile.json");
```
```
### Using url variables
```javascript
$rast.get("/test/:test");
server.json((res, vars) => {
return {"message": "You are in /test/" + vars.test};
});
```
### Not found page
```javascript
$rast.notFound();
server.json(() => {
return {"message": "Not Found 🙁"};
});
```
{
"message": "Hello, World!"
}
require("../rastapi");
const server = new $rast.httpServer();
$rast.get("/");
server.json(() => {
return {"message": "Hello World ✨"};
});
$rast.get("/test");
server.file(() => "../api.json");
server.listen().then(() => console.log("I am listening ✨"));