Skip to content

Bootstrap

defineBootstrap is the main entry point of GamanJS. This function creates a Gaman instance and provides access to the mount() and mountServer() methods.

import { defineBootstrap } from 'gaman';
import router from './router';
defineBootstrap(async (app) => {
// Mount router, middleware, or exception handler
app.mount(router);
// Start HTTP server
app.mountServer({ http: 3431 });
});

The mount() method is used to register:

TypeDescription
RoutesResult of composeRouter() — registers all defined routes
MiddlewareResult of composeMiddleware()() — global middleware that runs on all routes
ExceptionHandlerResult of composeException() — global error handler
import { defineBootstrap } from 'gaman';
import router from './router';
import AuthMiddleware from './module/middlewares/AuthMiddleware';
import GlobalExceptionHandler from './module/exceptions/GlobalException';
defineBootstrap(async (app) => {
// Mount global middleware (called as function to set config)
app.mount(AuthMiddleware());
// Mount global exception handler
app.mount(GlobalExceptionHandler);
// Mount routes
app.mount(router);
app.mountServer({ http: 3431 });
});

Note: The order of mount() for middleware affects execution order based on priority. See Middleware for priority system details.

Starts the HTTP server with the given configuration.

app.mountServer({ http: 3431 });
app.mountServer({
http: {
port: 3431,
host: 'localhost', // default: 'localhost'
maxRequestBodySize: 1024 * 1024 * 50, // 50MB
reusePort: false, // default: false
development: true, // default: false
},
});
PropertyTypeDefaultDescription
portnumber3431HTTP server port
hoststring'localhost'Server hostname. Use '0.0.0.0' to accept from all interfaces
maxRequestBodySizenumberMaximum request body size in bytes
reusePortbooleanfalseEnable SO_REUSEPORT socket option
developmentbooleanfalseDevelopment mode — shows detailed error stacks