Code generation
ts
import { createHub, routeStore } from "@duplojs/http";
import { createHttpServer } from "@duplojs/http/node";
import { codeGeneratorPlugin } from "@duplojs/http/codeGenerator";
const hub = createHub({ environment: "DEV" })
.register(routeStore.getAll())
.plug(codeGeneratorPlugin({ outputFile: "types.d.ts" }));
await createHttpServer(
hub,
{
host: "localhost",
port: 1506,
},
);To generate typing for all your routes, use the codeGeneratorPlugin function from @duplojs/http/codeGenerator in the Hub and start with the environment variable set to DEV or BUILD.
The outputFile parameter lets you define which file the code will be written to.
WARNING
You must have an HTTP server implementation, because the plugin hooks into beforeStartServer, which only runs via interface functions like createHttpServer. Run with the Hub configured in BUILD mode so the HTTP server doesn’t start.
