Skip to main content

@hile/http-next

Serve Next.js pages and Hile API controllers from one Koa server and one port.

Choose This Package When

Use When

Use HttpNext 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-next for a pure API service; use @hile/http.
  • Do not put Hile controllers inside src/app unless you intentionally change controllerDirectory.

Install

Imports

Copy-Paste Example

More Examples

Recommended layout:
Use 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

  • HttpNext wraps an internal Http instance.
  • 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.
  • specialControllers load 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 with shutdown.
  • Controllers live under the configured controller directory.
  • API routes use the configured prefix, default /-.
  • Next.js production build runs before hile start in production.

HttpNext Fullstack App

Complete Example

Boot:
API controller:
Next.js page:
Model:

Package-Local AI Guide

This package also ships AI.md in npm so agents can read accurate examples after installation.