Sfoglia il codice sorgente

Add velocy, a minimal javascript framework (#8403)

* add velocy, Node.js framework

* add more info on readme

* bump velocy: 0.0.9 -> 0.0.12

* fixes the dockers issue of lower case naming

* removes the `.vagrant` directory

* Update dockerfile to fix the CI issue.

* add JSON + remove global strings/config
Ishtmeet Singh 1 anno fa
parent
commit
63b04519a4

+ 1 - 0
frameworks/JavaScript/velocy/.gitignore

@@ -0,0 +1 @@
+node_modules/

+ 4 - 0
frameworks/JavaScript/velocy/README.md

@@ -0,0 +1,4 @@
+# Velocy
+A minimal high performance web framework for Node.js. The goal and design of Velocy is to be a high performance web framework without installing any dependencies at all! It is a part of an [open source book](https://github.com/ishtms/learn-nodejs-hard-way) that I am writing.
+
+Github repo - [Velocy](https://github.com/ishtms/velocy)

+ 46 - 0
frameworks/JavaScript/velocy/app.js

@@ -0,0 +1,46 @@
+const cluster = require("node:cluster");
+const os = require("node:os");
+const process = require("node:process");
+const { SimpleRouter, createServer } = require("velocy");
+
+if (cluster.isPrimary) {
+    console.log(`Primary ${process.pid} is running`);
+
+    const numCPUs = os.cpus().length;
+    for (let i = 0; i < numCPUs; i++) {
+        cluster.fork();
+    }
+
+    cluster.on("exit", (worker) => {
+        console.log(`worker ${worker.process.pid} died`);
+        process.exit(1);
+    });
+} else {
+    const router = new SimpleRouter();
+
+    router.get("/plaintext", (req, res) => {
+        let p = "Hello, World!";
+        res.writeHead(200, {
+            "content-type": "text/plain",
+            "content-length": p.length,
+            Server: "Velocy",
+        });
+        res.end(p);
+    });
+
+    router.get("/json", (req, res) => {
+        let p = JSON.stringify({ message: "Hello, World!" });
+
+        res.writeHead(200, {
+            "content-type": "application/json",
+            "content-length": p.length,
+            Server: "Velocy",
+        });
+
+        res.end(p);
+    });
+
+    createServer(router).listen(8080);
+
+    console.log(`Worker ${process.pid} started`);
+}

+ 26 - 0
frameworks/JavaScript/velocy/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+    "framework": "velocy",
+    "tests": [
+        {
+            "default": {
+                "plaintext_url": "/plaintext",
+                "json_url": "/json",
+                "port": 8080,
+                "approach": "Realistic",
+                "classification": "Micro",
+                "database": "None",
+                "framework": "velocy",
+                "language": "JavaScript",
+                "flavor": "None",
+                "orm": "None",
+                "platform": "nodejs",
+                "webserver": "None",
+                "os": "Linux",
+                "database_os": "None",
+                "display_name": "velocy",
+                "notes": "",
+                "versus": "nodejs"
+            }
+        }
+    ]
+}

+ 14 - 0
frameworks/JavaScript/velocy/config.toml

@@ -0,0 +1,14 @@
+[framework]
+name = "velocy"
+
+[main]
+urls.plaintext = "/plaintext"
+approach = "Realistic"
+classification = "Micro"
+database = "None"
+database_os = "None"
+os = "Linux"
+orm = "None"
+platform = "nodejs"
+webserver = "None"
+versus = "nodejs"

+ 5 - 0
frameworks/JavaScript/velocy/package.json

@@ -0,0 +1,5 @@
+{
+    "dependencies": {
+        "velocy": "0.0.13"
+    }
+}

+ 6 - 0
frameworks/JavaScript/velocy/velocy.dockerfile

@@ -0,0 +1,6 @@
+FROM node:20-slim
+WORKDIR /usr/app
+COPY ./ /usr/app
+RUN npm install
+EXPOSE 8080
+CMD ["node", "app.js"]