In Minimajs, everything is a module.
And a module is essentially an asynchronous function.
Creating a Module
src/payments/index.ts
import { type App } from "@minimajs/server";
async function getPayments() {
// Fetch payments somehow.
return [];
}
export async function paymentModule(app: App) {
app.get("/", getPayments);
}
Register module
src/index.ts
app.register(paymentModule, { prefix: "/payments" });
or root level
src/index.ts
app.register(paymentModule);
In this example:
- We define a module named
paymentModuleinsrc/payments/index.ts. - This module exports an asynchronous function that takes an
Appas a parameter. - Within the module function, we define a route handler
getPaymentsto handle requests to the/paymentsendpoint. - Finally, we register the
paymentModulewith the application, specifying the prefix/paymentsfor its routes insrc/index.ts.
This approach allows for a modular and organized structure, making it easier to manage and maintain your application's codebase.