refactor: reduce duplication with shared Env type, renderPage helper, and email helper#160
Merged
refactor: reduce duplication with shared Env type, renderPage helper, and email helper#160
Conversation
… and email helper
- Export shared Env type alias from types.ts, replacing inline { Bindings; Variables } across 10 files
- Extract renderPage() helper to eliminate repeated c.html/DOCTYPE pattern (~25 call sites)
- Extract sendOrLogVerificationEmail() in emailAuth.ts to consolidate duplicate email-sending logic
- Remove redundant trim check in ChatRoom.ts (value was already trimmed)
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Hono app to reduce repeated type boilerplate and duplicated HTML/email helper patterns, centralizing common logic in shared types/helpers.
Changes:
- Added a shared exported
Envtype inhono/types.tsand updated routes/middleware to use it. - Introduced
renderPage()helper to standardize<!DOCTYPE html>...rendering for JSX pages. - Consolidated email verification sending/logging logic into
sendOrLogVerificationEmail().
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| hono/types.ts | Exports shared Env type used across the app. |
| hono/testApp.ts | Updates test middleware typing to use Env. |
| hono/routes/ws.ts | Uses Hono<Env> and simplifies imports. |
| hono/routes/testAuth.ts | Uses Hono<Env> for consistent typing. |
| hono/routes/messages.ts | Uses Hono<Env> for consistent typing. |
| hono/routes/index.tsx | Uses renderPage() and Env to reduce duplication. |
| hono/routes/emailAuth.ts | Uses renderPage(), introduces sendOrLogVerificationEmail(), and switches to Env. |
| hono/routes/channels.ts | Uses Hono<Env> for consistent typing. |
| hono/routes/auth.ts | Replaces local Env alias with shared Env type. |
| hono/helpers/renderPage.ts | Adds helper to render pages with a <!DOCTYPE html> prefix. |
| hono/durableObjects/ChatRoom.ts | Removes redundant empty-message guard after earlier validation already trims/validates. |
| hono/auth/requireUser.ts | Uses createMiddleware<Env> for consistent typing. |
| hono/app.tsx | Updates app/middleware generics to use shared Env. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Envtype: Exporttype Env = { Bindings: Bindings; Variables: Variables }fromhono/types.ts, replacing the inline{ Bindings: Bindings; Variables: Variables }pattern across 10 filesrenderPage()helper: Newhono/helpers/renderPage.tseliminates the repeatedc.html(${await Page(...)})pattern used in ~25 call sites acrossemailAuth.tsandindex.tsxsendOrLogVerificationEmail()helper: Consolidates duplicate email-sending logic inemailAuth.ts(dev-mode logging vs production Resend API) into a single function.trim()call inChatRoom.tswhere the value was already trimmed on the previous lineNet change: -2 lines across 13 files. All 98 tests pass, lint clean, build succeeds.