Properties

Main

Mandarine.TS contains a property structure that allows the developer to modify some of the default behaviors of the framework as well as letting the developer create & configure their own properties to be used across the application.

Structure (Click here for more):

{
        [prop: string]: any,
        mandarine: {
            server: {
                host?: string,
                port: number,
                responseType?: MandarineMVC.MediaTypes
            } & any,
            resources: {
                staticRegExpPattern?: string,
                staticFolder?: string,
                staticIndex?: string,
                cors?: MandarineMVC.CorsMiddlewareOption
            } & any,
            templateEngine: {
                engine: Mandarine.MandarineMVC.TemplateEngine.Engines,
                path: string
            } & any,
            dataSource?: {
                dialect: Mandarine.ORM.Dialect.Dialects,
                data: {
                    host: string,
                    port?: number,
                    username: string,
                    password: string,
                    database: string,
                    poolSize?: number
                } & any
            } & any
        } & any
}

Defaults:

{
    mandarine: {
        server: {
            host: "0.0.0.0",
            port: 8080,
            responseType: Mandarine.MandarineMVC.MediaTypes.TEXT_HTML
        },
        resources: {
            staticFolder: "./src/main/resources/static",
            staticRegExpPattern: "/(.*)"
        },
        templateEngine: {
            path: "./src/main/resources/templates",
            engine: "ejs"
        }
    }
}

Setting your own properties

In order to set your own properties, you must create a JSON file. This JSON file needs to have & respect the structure above, this means, you can add and override values, but you cannot change the structure.

Your configuration file does not have to necessarily the mandarine's essential configurations such as the server or the template engine information. If you decide to ignore some of these properties, Mandarine will set its default values to those that have been ignored previously.

In order to use your configuration file, you must:

  • Create a file in "./src/main/resources" called "properties.json".

    • "./src/main/resources/properties.json"

    • File must be called properties.json

  • Set your own property keys & values in this file.

Example

# ./src/main/resources/properties.json

{
    "mandarine": {
        "server": {
            "port": 8000
        },
        "myToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
    },
    "myCustomPropertyKey": "My custom value"
}

Last updated