JS20

Documentation

JS20 - Documentation

API Reference

AppConfig

When running new App(config), you can pass a config object to customize the app behavior. All config options are optional.

/**
 * Configuration for the App
 * @param isProduction Whether the app is running in production mode, defaults to true
 * @param server Configuration for the web server (Express, etc.)
 * @param handleError A custom error handler to format errors returned to clients
 */
export interface AppConfig {
    isProduction?: boolean;
    server?: WebServerConfig;
    handleError?: ErrorHandler;
}

/**
 * Response returned when an error has been handled
 * Will return as JSON to the client with the provided http code
 * @param error The user-facing error message, defaults to "Unknown error"
 * @param code The HTTP status code to return, defaults to 500
 * @param additionalInfo Any additional info to return to the client
 */
export interface ErrorResponse {
    error: string;
    code: number;
    additionalInfo?: any;
}

/**
 * A function that handles errors thrown in endpoints
 */
export type ErrorHandler = (error: any) => Promise<ErrorResponse>;

/**
 * Configuration for the web server
 * @param type The type of web server to use, defaults to 'express'
 * @param port The port to run the web server on, defaults to 3000 or process.env.PORT
 * @param allowedOrigins A list of allowed origins for CORS, if not provided, CORS is set to allow all origins
 * @param rateLimit Configuration for rate limiting
 */
export interface WebServerConfig {
    type?: WebServerType;
    port?: number;
    allowedOrigins?: string[];
    rateLimit?: RateLimitConfig;
}

/**
 * Configuration for rate limiting
 * @param windowMs The time frame for which requests are checked/remembered (in milliseconds), defaults to 15 minutes
 * @param max The maximum number of connections to allow during the windowMs time frame, defaults to 300
 */
export interface RateLimitConfig {
    windowMs?: number;
    max?: number;
}

/**
 * The type of web server to use under the hood
 */
export enum WebServerType {
    express = 'express',
}

Default values:

const defaultConfig: AppConfig = {
    isProduction: true,
    server: {
        type: WebServerType.express,
        port: 3000,
        allowedOrigins: [],
        rateLimit: {
            windowMs: 15 * 60 * 1000,
            max: 300,
        }
    },
}

GenerateConfig

When running app.generate(config), you can pass a config object to customize the generation behavior. All config options are optional.

/**
 * Configuration for code generation
 * @param entryPath An entry path to your TS types, so the framework can rebuild them for frontend
 * @param outputs Where to save the generated files, can be multiple files
 * @param appName The name of your app, will be added as a comment in the top of the generated files
 * @param version The version of your app, will be added as a comment in the top of the generated files
 * @param comment Any extra comment to add in the top of the generated files
 * @param modelsName The name of your Models interface, by default assumes "Models"
 * @param baseUrl The base URL of your app, used to generate the client SDK
 * @param prettierOptions Options to pass to Prettier
 */
export interface GenerateConfig {
    entryPath: string;
    outputs: string[];
    appName?: string;
    version?: string;
    comment?: string;
    modelsName?: string;
    baseUrl: string;
    prettierOptions?: PrettierOptions;
    quiet?: boolean;
}
JS20