createApp(options) API Reference

Module: webspresso
Signature: createApp(options: CreateAppOptions): CreateAppResult
TypeScript Definition: index.d.ts


1. Parameters (CreateAppOptions) #

OptionTypeDefaultDescription
pagesDir (required)string—Absolute or relative path to the directory containing .njk page templates and .js route handlers.
viewsDirstring'views'Directory containing Nunjucks layouts and partials.
publicDirstring | false'public'Directory for static asset serving. Set false to disable static serving.
dbDatabaseInstancenullKnex database instance created via createDatabase().
authAuthManagernullAuthentication manager created via createAuth().
pluginsPlugin[][]Array of Webspresso plugin instances (e.g. adminPanelPlugin, corsPlugin).
setupRoutes(app: Express) => voidnullCallback hook to register custom Express routes before 404/500 handlers.
trustProxyboolean | number | stringundefinedExpress trust proxy setting (e.g. 1 for one reverse proxy hop).
pageAssetsboolean | PageAssetsOptionsfalseAutomatic route-matching CSS and JS asset injection.
pageAssets.enabledbooleanfalseEnable automatic per-page asset resolution.
pageAssets.stylesheetsbooleantrueAuto-link public/css/pages/<route>.css.
pageAssets.scriptsbooleantrueAuto-link public/js/pages/<route>.js.
server.shutdownShutdownOptions{}Graceful shutdown and socket draining configuration.
server.shutdown.enabledbooleantrueEnable SIGINT/SIGTERM lifecycle management.
server.shutdown.mode'graceful' | 'force''graceful'Shutdown mode. 'graceful' drains in-flight requests; 'force' closes sockets immediately.
server.shutdown.timeoutnumber10000Milliseconds to wait before force closing remaining connections.
server.compressionbooleanfalseEnable zero-dependency streaming zlib compression (Brotli, Gzip, Deflate).
assetsAssetManagerOptions{}Asset versioning, cache-busting, and CDN prefixing configuration.
assets.versionstringundefinedQuery string version tag (e.g. ?v=1.2.3).
assets.manifestPathstringundefinedAbsolute path to Vite/Webpack .vite/manifest.json.
assets.prefixstring''CDN URL prefix (e.g. https://cdn.example.com).
errorPagesErrorPagesOptions{}Custom error and 404 template paths or handlers.

2. Return Value (CreateAppResult) #

createApp() returns an object containing initialized framework instances:

TYPESCRIPT
interface CreateAppResult {
  app: WebspressoApplication;      // Configured Express 5 application instance
  nunjucksEnv: nunjucks.Environment; // Nunjucks environment instance
  pluginManager: PluginManager;   // Plugin manager registry
  authMiddleware: RequestHandler; // Session/Auth middleware
  shutdownManager: ShutdownManager; // Graceful shutdown manager
}

3. Properties on app (WebspressoApplication) #

Property / MethodTypeDescription
app.routesRouteTableImmutable route registry with .list(), .match(method, path), and .tree().
app.serviceRegistryServiceRegistryIn-process business services registry.
app.close()() => Promise<void>Idempotent method to gracefully shut down the server and dispose all plugins.
app.setErrorHandler()(handler) => voidRegister a custom central error boundary handler.
app.locals.dbDatabaseInstanceBound database instance.
Created · Updated