@gieo/express 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var http_1 = require("http");
4
+ var url_1 = require("url");
5
+ var ExpressPlus = /** @class */ (function () {
6
+ function ExpressPlus() {
7
+ this.routes = {
8
+ GET: [],
9
+ POST: [],
10
+ PUT: [],
11
+ PATCH: [],
12
+ DELETE: [],
13
+ };
14
+ }
15
+ ExpressPlus.prototype.addRoute = function (method, path, handler) {
16
+ this.routes[method].push({ path: path, handler: handler });
17
+ };
18
+ ExpressPlus.prototype.get = function (path, handler) {
19
+ this.addRoute("GET", path, handler);
20
+ };
21
+ ExpressPlus.prototype.post = function (path, handler) {
22
+ this.addRoute("POST", path, handler);
23
+ };
24
+ ExpressPlus.prototype.put = function (path, handler) {
25
+ this.addRoute("PUT", path, handler);
26
+ };
27
+ ExpressPlus.prototype.patch = function (path, handler) {
28
+ this.addRoute("PATCH", path, handler);
29
+ };
30
+ ExpressPlus.prototype.delete = function (path, handler) {
31
+ this.addRoute("DELETE", path, handler);
32
+ };
33
+ ExpressPlus.prototype.listen = function (port, callback) {
34
+ var _this = this;
35
+ var server = (0, http_1.createServer)(function (req, res) {
36
+ var method = req.method;
37
+ var parsedUrl = (0, url_1.parse)(req.url || "", true);
38
+ var pathname = parsedUrl.pathname || "/";
39
+ var route = _this.routes[method].find(function (r) { return r.path === pathname; });
40
+ if (route) {
41
+ req.query = parsedUrl.query;
42
+ route.handler(req, res);
43
+ }
44
+ else {
45
+ res.statusCode = 404;
46
+ res.end("Not Found");
47
+ }
48
+ });
49
+ server.listen(port, callback);
50
+ };
51
+ return ExpressPlus;
52
+ }());
53
+ exports.default = ExpressPlus;
package/dist/test.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var index_1 = require("./index");
4
+ var app = new index_1.default();
5
+ app.get("/", function (req, res) {
6
+ res.end("Hello, World!");
7
+ });
8
+ app.get("/hello", function (req, res) {
9
+ var name = req.query.name || "Guest";
10
+ res.end("Hello, ".concat(name, "!"));
11
+ });
12
+ app.post("/data", function (req, res) {
13
+ var body = "";
14
+ req.on("data", function (chunk) {
15
+ body += chunk.toString();
16
+ });
17
+ req.on("end", function () {
18
+ res.end("Received data: ".concat(body));
19
+ });
20
+ });
21
+ app.put("/update", function (req, res) {
22
+ res.end("Update successful");
23
+ });
24
+ app.patch("/modify", function (req, res) {
25
+ res.end("Modify successful");
26
+ });
27
+ app.delete("/delete", function (req, res) {
28
+ res.end("Delete successful");
29
+ });
30
+ app.listen(3000, function () {
31
+ console.log("Server is running on http://localhost:3000");
32
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@gieo/express",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "keywords": [],
7
+ "author": "",
8
+ "license": "ISC",
9
+ "devDependencies": {
10
+ "@types/node": "^24.2.0",
11
+ "jiti": "^2.5.1",
12
+ "typescript": "^5.9.2"
13
+ },
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ }
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { createServer, IncomingMessage, ServerResponse } from "http";
2
+ import { parse } from "url";
3
+
4
+ type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
5
+ type Handler = (
6
+ req: IncomingMessage & { query?: any },
7
+ res: ServerResponse
8
+ ) => void;
9
+
10
+ interface Route {
11
+ path: string;
12
+ handler: Handler;
13
+ }
14
+
15
+ export default class ExpressPlus {
16
+ private routes: Record<Method, Route[]> = {
17
+ GET: [],
18
+ POST: [],
19
+ PUT: [],
20
+ PATCH: [],
21
+ DELETE: [],
22
+ };
23
+
24
+ private addRoute(method: Method, path: string, handler: Handler): void {
25
+ this.routes[method].push({ path, handler });
26
+ }
27
+
28
+ get(path: string, handler: Handler): void {
29
+ this.addRoute("GET", path, handler);
30
+ }
31
+
32
+ post(path: string, handler: Handler): void {
33
+ this.addRoute("POST", path, handler);
34
+ }
35
+
36
+ put(path: string, handler: Handler): void {
37
+ this.addRoute("PUT", path, handler);
38
+ }
39
+
40
+ patch(path: string, handler: Handler): void {
41
+ this.addRoute("PATCH", path, handler);
42
+ }
43
+
44
+ delete(path: string, handler: Handler): void {
45
+ this.addRoute("DELETE", path, handler);
46
+ }
47
+
48
+ listen(port: number, callback: () => void): void {
49
+ const server = createServer((req, res) => {
50
+ const method = req.method as Method;
51
+ const parsedUrl = parse(req.url || "", true);
52
+ const pathname = parsedUrl.pathname || "/";
53
+
54
+ const route = this.routes[method].find((r) => r.path === pathname);
55
+
56
+ if (route) {
57
+ (req as any).query = parsedUrl.query;
58
+ route.handler(req as any, res);
59
+ } else {
60
+ res.statusCode = 404;
61
+ res.end("Not Found");
62
+ }
63
+ });
64
+
65
+ server.listen(port, callback);
66
+ }
67
+ }
package/src/test.ts ADDED
@@ -0,0 +1,31 @@
1
+ import ExpressPlus from "./index";
2
+ const app = new ExpressPlus();
3
+
4
+ app.get("/", (req, res) => {
5
+ res.end("Hello, World!");
6
+ });
7
+ app.get("/hello", (req, res) => {
8
+ const name = req.query.name || "Guest";
9
+ res.end(`Hello, ${name}!`);
10
+ });
11
+ app.post("/data", (req, res) => {
12
+ let body = "";
13
+ req.on("data", (chunk) => {
14
+ body += chunk.toString();
15
+ });
16
+ req.on("end", () => {
17
+ res.end(`Received data: ${body}`);
18
+ });
19
+ });
20
+ app.put("/update", (req, res) => {
21
+ res.end("Update successful");
22
+ });
23
+ app.patch("/modify", (req, res) => {
24
+ res.end("Modify successful");
25
+ });
26
+ app.delete("/delete", (req, res) => {
27
+ res.end("Delete successful");
28
+ });
29
+ app.listen(3000, () => {
30
+ console.log("Server is running on http://localhost:3000");
31
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "outDir":"./dist",
5
+ }
6
+ }