@hile/http-next
Serve Next.js pages and Hile API controllers from one Koa server and one port.Choose This Package When
Use When
UseHttpNext when a Next.js app and Hile API controllers should share the same HTTP server and port.
Do Not Use When
- Do not use
@hile/http-nextfor a pure API service; use@hile/http. - Do not put Hile controllers inside
src/appunless you intentionally changecontrollerDirectory.
Install
Imports
Copy-Paste Example
More Examples
Recommended layout:loadModel() from pages or controllers for domain logic. If a Next.js page uses runtime model data, mark the route dynamic:
Runtime And Lifecycle Notes
HttpNextwraps an internalHttpinstance.- It serves
publicPath, then.next/static, then Hile controllers, then Next.js as the fallback handler. - Development mode is determined by
process.env.NODE_ENV === 'development'. - Controller directory is
{cwd}/src/{controllerDirectory}in development and{cwd}/dist/{controllerDirectory}in production. specialControllersload additional controller roots with their own prefixes.
Anti-Patterns
- Putting API routes in Next.js when the app is intentionally using Hile controllers.
- Calling
loadService()at module top level in Next.js files. - Forgetting
cwd; relative controller and Next artifact paths depend on it.
Verification Checklist
HttpNext.start()close function is registered withshutdown.- Controllers live under the configured controller directory.
- API routes use the configured prefix, default
/-. - Next.js production build runs before
hile startin production.
Related Recipes
HttpNext Fullstack App
Complete Example
Boot:Package-Local AI Guide
This package also shipsAI.md in npm so agents can read accurate examples after installation.