Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unjs/h3
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.8.6
Choose a base ref
...
head repository: unjs/h3
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0
Choose a head ref
  • 16 commits
  • 41 files changed
  • 6 contributors

Commits on Oct 29, 2022

  1. chore(deps): update pnpm to v7.14.1 (#217)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Oct 29, 2022
    Copy the full SHA
    087de86 View commit details

Commits on Nov 2, 2022

  1. Copy the full SHA
    c5fb53d View commit details
  2. Copy the full SHA
    8b89f39 View commit details
  3. chore(deps): update all non-major dependencies (#218)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 2, 2022
    Copy the full SHA
    b96c58d View commit details
  4. chore(deps): update pnpm to v7.14.2 (#221)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 2, 2022
    Copy the full SHA
    41be7e3 View commit details
  5. chore(deps): update devdependency listhen to ^0.3.5 (#222)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 2, 2022
    Copy the full SHA
    f78778c View commit details

Commits on Nov 3, 2022

  1. Copy the full SHA
    e6a9f94 View commit details
  2. feat: add proxyRequest util (#226)

    pi0 authored Nov 3, 2022
    Copy the full SHA
    501f0c6 View commit details

Commits on Nov 15, 2022

  1. chore(deps): update devdependency listhen to v1 (#230)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 15, 2022
    Copy the full SHA
    cef2ff9 View commit details
  2. refactor: update repository

    pi0 committed Nov 15, 2022
    Copy the full SHA
    a138101 View commit details
  3. chore(deps): update pnpm to v7.16.0 (#227)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Nov 15, 2022
    Copy the full SHA
    8d8f76f View commit details
  4. Copy the full SHA
    5234270 View commit details
  5. Copy the full SHA
    dc8ee81 View commit details
  6. Copy the full SHA
    e2c2144 View commit details
  7. Copy the full SHA
    43db151 View commit details
  8. chore(release): 1.0.0

    pi0 committed Nov 15, 2022
    Copy the full SHA
    e8a7b6b View commit details
Showing with 1,705 additions and 1,871 deletions.
  1. +7 −3 .eslintrc
  2. +9 −217 CHANGELOG.md
  3. +1 −1 LICENSE
  4. +5 −2 README.md
  5. +13 −13 package.json
  6. +14 −11 playground/index.ts
  7. +6 −6 playground/server.cjs
  8. +171 −214 pnpm-lock.yaml
  9. +1 −1 renovate.json
  10. +47 −47 src/app.ts
  11. +37 −37 src/error.ts
  12. +45 −28 src/event/event.ts
  13. +17 −17 src/event/headers.ts
  14. +4 −4 src/event/index.ts
  15. +25 −25 src/event/response.ts
  16. +30 −30 src/event/utils.ts
  17. +7 −7 src/index.ts
  18. +36 −36 src/node.ts
  19. +37 −37 src/router.ts
  20. +5 −4 src/types.ts
  21. +33 −39 src/utils/body.ts
  22. +17 −19 src/utils/cache.ts
  23. +3 −3 src/utils/consts.ts
  24. +11 −17 src/utils/cookie.ts
  25. +8 −8 src/utils/index.ts
  26. +66 −19 src/utils/proxy.ts
  27. +31 −37 src/utils/request.ts
  28. +58 −58 src/utils/response.ts
  29. +9 −9 src/utils/route.ts
  30. +160 −166 test/app.test.ts
  31. +120 −120 test/body.test.ts
  32. +55 −55 test/cookie.test.ts
  33. +36 −36 test/e2e.test.ts
  34. +61 −62 test/error.test.ts
  35. +175 −175 test/header.test.ts
  36. +53 −53 test/integrations.test.ts
  37. +28 −28 test/lazy.test.ts
  38. +65 −28 test/proxy.test.ts
  39. +137 −137 test/router.test.ts
  40. +59 −59 test/utils.test.ts
  41. +3 −3 vitest.config.ts
10 changes: 7 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
"eslint-config-unjs"
],
"rules": {
"no-use-before-define": "off",
"vue/one-component-per-file": "off"
"unicorn/no-null": 0,
"unicorn/prevent-abbreviations": 0,
"no-undef": 0,
"no-use-before-define": 0,
"unicorn/no-await-expression-member": 0,
"unicorn/no-useless-undefined": 0
}
}
226 changes: 9 additions & 217 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,233 +2,25 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.0.0](https://github.com/unjs/h3/compare/v0.8.6...v1.0.0) (2022-11-15)

## v0.8.6

[compare changes](https://github.com/unjs/h3/compare/v0.8.5...v0.8.6)


### 🚀 Enhancements

- **createError:** Support `status` and `statusText` ([#213](https://github.com/unjs/h3/pull/213))
- Add `sendProxy` ([#214](https://github.com/unjs/h3/pull/214))
- Add `toJSON` method to errors ([#215](https://github.com/unjs/h3/pull/215))

### 🔥 Performance

- **router:** Avoid using `new URL` ([7162e09](https://github.com/unjs/h3/commit/7162e09))

### 🩹 Fixes

- Implement `keys`, `values`, `entries` and iterator for H3Event ([b0f8d43](https://github.com/unjs/h3/commit/b0f8d43))

### ✅ Tests

- Add more tests for empty and non-present ([#206](https://github.com/unjs/h3/pull/206))
- Update getRequestHeader+cookie test ([9e5551e](https://github.com/unjs/h3/commit/9e5551e))

### ❤️ Contributors

- Daniel Roe
- Pooya Parsa
- Tobias Diez

## v0.8.5

[compare changes](https://github.com/unjs/h3/compare/v0.8.4...v0.8.5)


### 🚀 Enhancements

- Normalize request headers ([d141f81](https://github.com/unjs/h3/commit/d141f81))

### 🩹 Fixes

- **writeEarlyHints:** Avoid depending on node 18 api until stablized ([f935fac](https://github.com/unjs/h3/commit/f935fac))

### 🏡 Chore

- Only run tests once during release ([#204](https://github.com/unjs/h3/pull/204))

### ❤️ Contributors

- Chris
- Pooya Parsa

## v0.8.4

[compare changes](https://github.com/unjs/h3/compare/v0.8.3...v0.8.4)


### 🩹 Fixes

- Always set lowecase headers ([09b8fcc](https://github.com/unjs/h3/commit/09b8fcc))

### ❤️ Contributors

- Pooya Parsa

## v0.8.3

[compare changes](https://github.com/unjs/h3/compare/v0.8.2...v0.8.3)


### 🩹 Fixes

- **writeEarlyHints:** Join headers with comma ([#203](https://github.com/unjs/h3/pull/203))
- **readRawBody:** Resolve to undefined when content-length is zero or unspecified ([#197](https://github.com/unjs/h3/pull/197))

### 🌊 Types

- `next` is always passed to `NodeMiddleware` ([6617e48](https://github.com/unjs/h3/commit/6617e48))

### ❤️ Contributors

- Daniel Roe
- Pooya Parsa

## v0.8.2

[compare changes](https://github.com/unjs/h3/compare/v0.8.1...v0.8.2)


### 🚀 Enhancements

- **writeEarlyHints:** Handle object-format early hints ([#202](https://github.com/unjs/h3/pull/202))

### 🏡 Chore

- Typo ([47a507a](https://github.com/unjs/h3/commit/47a507a))

### ❤️ Contributors

- Daniel Roe
- Pooya Parsa

## v0.8.1

[compare changes](https://github.com/unjs/h3/compare/v0.8.0...v0.8.1)


### 🩹 Fixes

- Update radix3 ([a45afba](https://github.com/unjs/h3/commit/a45afba))
- Make `next` optional for `NodeMiddleware` type ([5b16a2c](https://github.com/unjs/h3/commit/5b16a2c))

### 🏡 Chore

- Manually update changelog ([32d8eda](https://github.com/unjs/h3/commit/32d8eda))

### ❤️ Contributors

- Pooya Parsa

## v0.8.0

[compare changes](https://github.com/unjs/h3/compare/v0.7.20...v0.8.0)

### ⚠️ Breaking changes

H3 API and exports are updated in order to reduce dependency on Node.js and future possibilities.

- All handlers should be defined with `eventHandler()` wrapper otherwise a warning will be shown suggesting this change for you.
- h3 `app` instance created by `createApp` is not a Node.js listener with `(req, res) => {}` signature anymore. You can convert h3 app into a Node.js listener using `toNodeListener(app)`.
- Compatibility api to support mixed `req.event` and `res.event` is dropped. If you had custom utils depending on this, you might need to change them.
- Node.js/Express-style middleware with `(req, res, next?) = {}` signature are not longer automatically converted to event handler format. You can convert them using new `fromNodeMiddleware((req, res) => {})` utility.
- Some exported TypeScript interfaces and types are renamed or removed reflecting this change.

### 🚀 Enhancements

- Add `writeEarlyHints` utility ([#184](https://github.com/unjs/h3/pull/184))

### 🩹 Fixes

- **readBody, readRawBody:** Use global symbol ([#174](https://github.com/unjs/h3/pull/174))
- **sendRedirect:** Only encode required chars in meta tag ([a9b992e](https://github.com/unjs/h3/commit/a9b992e))
- **writeEarlyHints:** Call callback if not supported too ([10eab1b](https://github.com/unjs/h3/commit/10eab1b))
- **router:** Make router handler non preemtive by default ([#194](https://github.com/unjs/h3/pull/194))
- **error:** Remove default `statusMessage` from errors ([#195](https://github.com/unjs/h3/pull/195))
- **router:** Parse url using `URL` for pathname ([#196](https://github.com/unjs/h3/pull/196))

### 💅 Refactors

- ⚠️ Reduce Node.js dependency ([#178](https://github.com/unjs/h3/pull/178))

### 📖 Documentation

- Add `sendStream` to the utils list ([d58fad8](https://github.com/unjs/h3/commit/d58fad8))

### 📦 Build

- Add `package.json` to subpath exports ([#186](https://github.com/unjs/h3/pull/186))

### ❤️ Contributors

- Alexander Lichter
- Christopher King
- Daniel Roe
- Pooya Parsa

## v0.7.20


### 🩹 Fixes

- **readBody, readRawBody:** Use global symbol (#174)
- **sendRedirect:** Only encode required chars in meta tag (a9b992e)

### ❤️ Contributors

- Christopher King
- Pooya Parsa

## main (v0.7.19..main)


### 🩹 Fixes

- Use named type imports from `http` (#173)

### 🏡 Chore

- Update unbuild (1568874)

### ❤️ Contributors

- Daniel Roe
- Pooya Parsa

## main (v0.7.18..main)


### 📦 Build

- Hotfix for unbuild issue (1564761)

### ❤️ Contributors

- Pooya Parsa

## main (v0.7.17..main)

### ⚠ BREAKING CHANGES

### 🚀 Enhancements
* drop deprecated util aliases

- Add `H3Event`, `H3Response` and `H3Headers` (#119)
### Features

### 🩹 Fixes
* add `proxyRequest` util ([#226](https://github.com/unjs/h3/issues/226)) ([501f0c6](https://github.com/unjs/h3/commit/501f0c6e623ea827d47691046f3c7319f5ac4651))

- **sendRedirect:** Avoid double encoding (04b432c)

### 🏡 Chore
### Bug Fixes

- Update deps and use changelogen (2c08445)
- Update vitest setup (77eded0)
* import type from correct location ([#219](https://github.com/unjs/h3/issues/219)) ([8b89f39](https://github.com/unjs/h3/commit/8b89f3927faed6cdd4cce6650f54d7b0ee77c229))
* **router:** throw 404 for intermediate matches ([43db151](https://github.com/unjs/h3/commit/43db151e32dece4d98a8a361de98a28b232efad9))

### ❤️ Contributors

- Daniel Roe
- Pooya Parsa
* drop deprecated util aliases ([dc8ee81](https://github.com/unjs/h3/commit/dc8ee81799bf93148ef686b3434287858afdafa0))

### [0.7.17](https://github.com/unjs/h3/compare/v0.7.16...v0.7.17) (2022-08-30)

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Nuxt Contrib
Copyright (c) Pooya Parsa <pooya@pi0.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ pnpm add h3

```ts
import { createServer } from 'http'
import { createApp, eventHandler } from 'h3'
import { createApp, eventHandler, toNodeListener } from 'h3'

const app = createApp()
app.use('/', eventHandler(() => 'Hello world!'))
@@ -88,7 +88,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.req.url }))
app.use('/api', eventHandler((event) => ({ url: event.node.req.url }))

// We can have better matching other than quick prefix match
app.use('/odd', eventHandler(() => 'Is odd!'), { match: url => url.substr(1) % 2 })
@@ -137,6 +137,7 @@ H3 has concept of compasable utilities that accept `event` (from `eventHandler((
- `assertMethod(event, expected, allowHead?)`
- `createError({ statusCode, statusMessage, data? })`
- `sendProxy(event, { target, headers?, fetchOptions?, fetch?, sendStream? })`
- `proxyRequest(event, { target, headers?, fetchOptions?, fetch?, sendStream? })`
👉 You can learn more about usage in [JSDocs Documentation](https://www.jsdocs.io/package/h3#package-functions).
@@ -146,6 +147,8 @@ More composable utilities can be found in community packages.
- `validateBody(event, schema)` from [h3-typebox](https://github.com/kevinmarrec/h3-typebox)
- `validateQuery(event, schema)` from [h3-typebox](https://github.com/kevinmarrec/h3-typebox)
- `useValidatedBody(event, schema)` from [h3-zod](https://github.com/wobsoriano/h3-zod)
- `useValidatedQuery(event, schema)` from [h3-zod](https://github.com/wobsoriano/h3-zod)
## License
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "h3",
"version": "0.8.6",
"version": "1.0.0",
"description": "Tiny JavaScript Server",
"repository": "unjs/h3",
"license": "MIT",
@@ -30,30 +30,30 @@
},
"dependencies": {
"cookie-es": "^0.5.0",
"destr": "^1.2.0",
"radix3": "^0.2.1",
"ufo": "^0.8.6"
"destr": "^1.2.1",
"radix3": "^1.0.0",
"ufo": "^1.0.0"
},
"devDependencies": {
"0x": "^5.4.1",
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@types/express": "^4.17.14",
"@types/node": "^18.11.7",
"@types/node": "^18.11.9",
"@types/supertest": "^2.0.12",
"@vitest/coverage-c8": "^0.24.3",
"@vitest/coverage-c8": "^0.25.2",
"autocannon": "^7.10.0",
"changelogen": "^0.3.5",
"changelogen": "^0.4.0",
"connect": "^3.7.0",
"eslint": "^8.26.0",
"eslint": "^8.27.0",
"eslint-config-unjs": "^0.0.2",
"express": "^4.18.2",
"get-port": "^6.1.2",
"jiti": "^1.16.0",
"listhen": "^0.3.4",
"node-fetch-native": "^0.1.8",
"listhen": "^1.0.0",
"node-fetch-native": "^1.0.1",
"supertest": "^6.3.1",
"typescript": "^4.8.4",
"unbuild": "^0.9.4",
"vitest": "^0.24.3"
"vitest": "^0.25.2"
},
"packageManager": "pnpm@7.14.0"
"packageManager": "pnpm@7.16.0"
}
25 changes: 14 additions & 11 deletions playground/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { listen } from 'listhen'
import { createApp, createRouter, eventHandler, toNodeListener, parseCookies, createError } from '../src'
import { listen } from "listhen";
import { fetch } from "node-fetch-native";
import { createApp, createRouter, eventHandler, toNodeListener, parseCookies, createError, proxyRequest } from "../src";

const app = createApp({ debug: true })
const app = createApp({ debug: true });
const router = createRouter()
.get('/', eventHandler(() => 'Hello World!'))
.get('/error/:code', eventHandler((event) => {
throw createError({ statusCode: parseInt(event.context.params.code) })
}))
.get('/hello/:name', eventHandler((event) => {
return `Hello ${parseCookies(event)}!`
.get("/", eventHandler(event => proxyRequest(event, "http://icanhazip.com", {
fetch
})))
.get("/error/:code", eventHandler((event) => {
throw createError({ statusCode: Number.parseInt(event.context.params.code) });
}))
.get("/hello/:name", eventHandler((event) => {
return `Hello ${parseCookies(event)}!`;
}));

app.use(router)
app.use(router);

listen(toNodeListener(app))
listen(toNodeListener(app));
Loading