Custom Web Server Changes
This chapter covers upgrades for two types of legacy custom Server APIs:
- unstableMiddleware
- Hook
These two approaches are mutually exclusive in the legacy version. When migrating, please choose the corresponding path based on the capabilities actually used in the project.
unstableMiddleware
Core Differences
- File Structure:
server/index.ts→server/modern.server.ts - Export Method:
unstableMiddlewarearray →defineServerConfig - Context API: Modern.js Server Context → Hono Context (
c.req/c.res) - Middleware Execution: Legacy version could skip calling
next(), new version must call it for subsequent chain execution - Response Method:
c.response.raw()→c.text()/c.json()
File and Export
Type and next Call
Context API Comparison
afterRender Hook
The afterRender Hook is used to process HTML after page rendering is complete. In the new version, you need to use renderMiddlewares to achieve the same functionality.
Core Differences
- File Structure:
server/index.ts→server/modern.server.ts - Export Method:
afterRenderinhookobject →renderMiddlewaresindefineServerConfig - Processing Method: Direct HTML string modification → Get and modify response through middleware