API Reference

JopiApp

Documentation for the JopiApp class.

JopiApp

The JopiApp class is the central entry point for a JopiJS application. It is responsible for initializing the environment, configuring the web server, and setting up global behaviors like authentication, caching, and middleware.

You typically interact with the singleton instance jopiApp exported from jopijs/core.

Usage

import { jopiApp } from "jopijs/core";

jopiApp.startApp(import.meta, (app) => {
    // Configure your application here
    app.configure_fileServer()
       .set_rootDir("public")
       .DONE_configure_fileServer();
       
    // ...
});

Methods

startApp(importMeta, configFunction)

Initializes and starts the JopiJS application.

  • importMeta: The import.meta object of your main application file. This is used to resolve paths correctly.
  • configFunction: A callback function that receives a JopiWebSiteBuilder instance, which you use to configure the application.

configure_fileServer()

Starts the fluent configuration for the static file server.

  • Returns: An object with methods to set the root directory (set_rootDir), handle 404s (set_onNotFound), and finish configuration (DONE_configure_fileServer).

fastConfigure_fileServer(options)

A shortcut to quickly configure the file server with an options object.

configure_jwtTokenAuth()

Starts the fluent configuration for JWT authentication. allows you to set the private key and configure the user store.

fastConfigure_jwtTokenAuth(privateKey, store)

Quickly configures JWT authentication.

  • privateKey: The secret key used for signing tokens.
  • store: Can be an array of hardcoded users or a custom authentication function.

configure_cors()

Starts the fluent configuration for Cross-Origin Resource Sharing (CORS).

fastConfigure_cors(allowedHosts)

Quickly configures CORS by providing a list of allowed hostnames (origins).

configure_middlewares()

Returns a builder to add global middlewares to your application.

  • add_middleware(method, middleware, options): Adds a middleware that runs before the request handler.
  • add_postMiddleware(method, middleware, options): Adds a middleware that runs after the request handler (to transform the response).

configure_cache()

Returns a builder to configure the page and API cache system.

add_sourceServer()

Registers a backend server source. This is used for load-balancing or proxying requests to other internal services.

add_specialPageHandler()

Allows you to register custom handlers for standard HTTP errors:

  • on_404_NotFound(handler)
  • on_500_Error(handler)
  • on_401_Unauthorized(handler)

configure_bundler()

Allows customization of the client-side bundler (Vite), such as excluding specific packages from the bundle.

configure_tailwindProcessor()

Allows configuration of the Tailwind CSS processor, or disabling it completely.