Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
reewrite package to reduce depencies (#4)
Browse files Browse the repository at this point in the history
Rewrite package to reduce dependencies and smaller functions
  • Loading branch information
Sirherobrine23 authored Oct 27, 2023
1 parent 6b5e270 commit f2353be
Show file tree
Hide file tree
Showing 21 changed files with 1,010 additions and 2,207 deletions.
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A fork of [express](https://github.com/expressjs/express) with patches and impro

```js
import neste from "neste";

const app = neste();

app.get("/", (req, res) => res.send("hello world"));
Expand All @@ -15,26 +14,47 @@ app.listen(3000, () => {
});
```

### Example

#### Standalone Nodejs

```js
const neste = require("neste"), app = neste();
import neste from "neste";
const app = neste();

app.get("/", (req, res) => res.send("hello world"));
app.get("/json", (req, res) => res.json({message: "hello world"}));
app.get("/", (req, res) => res.set("Content-Type", "text/html").send("<p>Hello world</p>"));

app.listen(3000, () => {
console.log("Listen on %s", 3000);
});
const PORT = Number(process.env.PORT || 3000);
app.listen(PORT, () => console.log("Listen on %s", PORT));
```

## Installation
#### Next.js API Routes

in a simple way:
- path: `/[...root].ts`

```sh
npm install --save neste
```js
import { Router } from "Neste";
const app = new Router();
export default app;

app.get("/", (req, res) => res.send(`<p>Hello from root API</p>`));
```

### Express middleware's
- path: `/form/[...formsSlugs].ts`

```js
import { Router } from "Neste";
const app = new Router({ "app path": "/form" });
export default app;

app.get("/", (req, res) => res.send(`<p>Hello from forms router</p>`));
```

## 3.x notice

version 3.0.0 is removing support for CommonJS, keeping only the ESM module. if you app/module is Commonjs module migrate to ESM or keep on ExpressJS.

## Express middleware's

> **Important**
> as a fork of express will be compatible some, probably some others have stopped in the future.
10 changes: 0 additions & 10 deletions export/index.cjs

This file was deleted.

11 changes: 0 additions & 11 deletions export/index.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions export/index.mjs

This file was deleted.

51 changes: 11 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
{
"name": "neste",
"description": "a express fork",
"version": "2.0.6",
"version": "3.0.0",
"author": "Matheus Sampaio Queiroga <[email protected]>",
"license": "MIT",
"type": "commonjs",
"main": "./export/index.cjs",
"types": "./export/index.d.ts",
"default": "./export/index.mjs",
"exports": {
".": {
"require": "./export/index.cjs",
"default": "./export/index.mjs",
"types": "./export/index.d.ts"
}
},
"type": "module",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Sirherobrine23/neste.git"
Expand All @@ -25,7 +17,6 @@
"keywords": [
"express",
"framework",
"sinatra",
"web",
"http",
"rest",
Expand All @@ -42,38 +33,18 @@
"postpack": "tsc --build --clean"
},
"devDependencies": {
"@types/accepts": "^1.3.5",
"@types/busboy": "^1.5.0",
"@types/content-disposition": "^0.5.5",
"@types/content-type": "^1.1.5",
"@types/cookie": "^0.5.1",
"@types/encodeurl": "^1.0.0",
"@types/escape-html": "^1.0.2",
"@types/finalhandler": "^1.2.0",
"@types/node": "^20.4.9",
"@types/proxy-addr": "^2.0.0",
"@types/qs": "^6.9.7",
"@types/range-parser": "^1.2.4",
"@types/send": "^0.17.1",
"@types/type-is": "^1.6.3",
"@types/vary": "^1.1.0",
"@types/ws": "^8.5.5",
"@types/busboy": "^1.5.2",
"@types/cookie": "^0.5.3",
"@types/node": "^20.8.9",
"@types/ws": "^8.5.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"dependencies": {
"accepts": "^1.3.8",
"busboy": "^1.6.0",
"content-disposition": "^0.5.4",
"content-type": "^1.0.5",
"cookie": "^0.5.0",
"finalhandler": "^1.2.0",
"path-to-regexp": "^6.2.1",
"proxy-addr": "^2.0.7",
"qs": "^6.11.2",
"send": "^0.18.0",
"type-is": "^1.6.18",
"vary": "^1.1.2",
"ws": "^8.13.0"
"ws": "^8.14.2",
"yaml": "^2.3.3"
}
}
13 changes: 13 additions & 0 deletions src/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { tmpdir } from "os";
import neste, { parseBody } from "./index.js";
const app = neste(), app2 = neste();

app.use(parseBody({ formData: { tmpFolder: tmpdir() }, formEncoded: { limit: -1 } }));

app.all("/", ({ path, reqPath, hostname, app, body }, res) => res.json({ path, reqPath, hostname, sets: Array.from(app.settings.entries()), body }));

app.use(app2).use("/gg", app2);
app2.settings.set("json space", 4);
app2.get("/gg", ({ path, reqPath, hostname, app, body }, res) => res.json({ path, reqPath, hostname, sets: Array.from(app.settings.entries()), body }));

app.listen(3000, () => console.log("Listen on %s", 3000));
Loading

0 comments on commit f2353be

Please sign in to comment.