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

feat: plain and web adapters #483

Merged
merged 7 commits into from
Aug 2, 2023
Merged

feat: plain and web adapters #483

merged 7 commits into from
Aug 2, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 2, 2023

πŸ”— Linked issue

Resolves #458

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds two new plain and web adapters to use h3 directly outside of Node.js environments!

Until now, it was only possible to use h3 in workers and lambda environments by either using Nitropack or custom code. With two new adapters, integration will be much more straightforward.

Two new utils depend on unenv framework to keep backward compatibility with Node.js API. This will be fully optional in the next major version of H3 once all h3 internal utils were decoupled.


Worker test deployment (deno deploy): https://rich-owl-49.deno.dev

import { createApp, eventHandler, toWebHandler } from "h3";

const app = createApp();

app.use(
  eventHandler((event) => ({
    path: event.path,
    message: "H3 works on Workers!",
  }))
);

Deno.serve(toWebHandler(app));

Total bundle size analysis (with esbuild):

Node: 19.4kb
Node min: 8.6kb
Node min gzip: 4.0kb

Web: 42kb (+22.6 kb)
Web min: 19.6kb (+11 kb)
Web min gzip: 8.1kb (+4.1 kb)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 changed the title feat: plain and web adapters feat: plain and web adapters Aug 2, 2023
@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #483 (cf33cd5) into main (c266755) will increase coverage by 0.23%.
Report is 2 commits behind head on main.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##             main     #483      +/-   ##
==========================================
+ Coverage   82.56%   82.79%   +0.23%     
==========================================
  Files          28       31       +3     
  Lines        3234     3424     +190     
  Branches      494      515      +21     
==========================================
+ Hits         2670     2835     +165     
- Misses        564      589      +25     
Files Changed Coverage Ξ”
src/adapters/plain.ts 87.12% <87.12%> (ΓΈ)
src/adapters/index.ts 100.00% <100.00%> (ΓΈ)
src/adapters/node.ts 85.08% <100.00%> (ΓΈ)
src/adapters/web.ts 100.00% <100.00%> (ΓΈ)
src/app.ts 96.70% <100.00%> (-0.73%) ⬇️
src/event/event.ts 90.36% <100.00%> (ΓΈ)
src/index.ts 100.00% <100.00%> (ΓΈ)
src/utils/cookie.ts 93.78% <100.00%> (+0.79%) ⬆️

... and 1 file with indirect coverage changes

@pi0 pi0 marked this pull request as ready for review August 2, 2023 12:45
@pi0
Copy link
Member Author

pi0 commented Aug 2, 2023

Let's try it!

@pi0 pi0 merged commit 368493a into main Aug 2, 2023
@pi0 pi0 deleted the feat/web-handler branch August 2, 2023 12:47
@pi0 pi0 mentioned this pull request Aug 4, 2023
Comment on lines +44 to +45
// Shim for Node.js request and response objects
// TODO: Remove in next major version

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually mean? I did not find any other information regarding this comment.
Does this mean that internal representation as IncomingMessage/ServerResponse will change at some point? If yes, is there discussions somewhere on the subject? If no, what was the idea?

For the context, I'm experimenting on generic handlers (and middlewares), and currently listing how each popular server implements handlers and middlewares.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more context on a dedicated repo https://github.com/magne4000/universal-handler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetch Adapter
2 participants