Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hebilicious h3 #2

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"singleQuote": false
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Routes are internally stored in a [Radix Tree](https://en.wikipedia.org/wiki/Rad

```js
// Handle can directly return object or Promise<object> for JSON response
app.use('/api', eventHandler((event) => ({ url: event.node.req.url })))
app.use('/api', eventHandler((event) => ({ url: getUrlPath(event) })))

// We can have better matching other than quick prefix match
app.use('/odd', eventHandler(() => 'Is odd!'), { match: url => url.substr(1) % 2 })
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "h3",
"version": "1.6.6",
"description": "Tiny JavaScript Server",
"repository": "unjs/h3",
"name": "@hebilicious/h3",
"version": "0.0.4",
"description": "Fork of unjs/h3",
"repository": "Hebilicious/h3",
"license": "MIT",
"sideEffects": false,
"exports": {
Expand All @@ -25,9 +25,10 @@
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test playground",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test playground -w",
"play": "jiti ./playground/index.ts",
"script": "jiti ./playground/script.ts",
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs",
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
"test": "pnpm lint && vitest run --coverage"
"test": "pnpm lint && NODE_OPTIONS=--experimental-vm-modules vitest --coverage"
},
"dependencies": {
"cookie-es": "^1.0.0",
Expand All @@ -40,6 +41,7 @@
},
"devDependencies": {
"0x": "^5.5.0",
"@cloudflare/workers-types": "^4.20230518.0",
"@types/express": "^4.17.17",
"@types/node": "^20.1.4",
"@types/supertest": "^2.0.12",
Expand All @@ -53,12 +55,14 @@
"get-port": "^7.0.0",
"jiti": "^1.18.2",
"listhen": "^1.0.4",
"miniflare": "^3.0.1",
"node-fetch-native": "^1.1.1",
"prettier": "^2.8.8",
"supertest": "^6.3.3",
"typescript": "^5.0.4",
"unbuild": "^1.2.1",
"vitest": "^0.31.1"
"vitest": "^0.31.1",
"vitest-environment-miniflare": "^2.14.0"
},
"packageManager": "pnpm@8.5.1"
}
}
21 changes: 21 additions & 0 deletions playground/script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createApp, createRouter, eventHandler, adapterFetch } from "../src";

const main = async () => {
const app = createApp();
const router = createRouter();
router.get(
"/hello",
eventHandler((event) => {
const request = event.request; // Request object, from the fetch API
return new Response(`hello ${request.method}`);
})
);
app.use(router);
const fetchResponse = adapterFetch(app);
const response = await fetchResponse(
new Request(new URL("http://localhost/hello"))
);
console.log(await response.text()); // hello GET
return response;
};
main();
Loading