Kamboja Application

KambojaJS application is the main application used to create the system. Behind the scene KambojaJS application generates all controllers into routes and assign a generic Http Handler associated with appropriate controller.

KambojaJS application designed to have the same API with Express so it will give a shorter learning curve for Express users.

To create instance of KambojaJS application simply call the KambojaApplication constructor from kamboja-express module.

import { KambojaApplication } from "kamboja-express"

let app = new KambojaApplication(__dirname).init()
app.listen(5000)

KambojaApplication(option)

Creates instance of KambojaJS application

Parameters:

  • option string or <Core.KambojaOption> If provided string the value will be used as rootPath of the application, else it can provided complete option described in KambojaOption

Kamboja.init()

Initialize KambojaJS instance, generate routes and assign route to appropriate generic http handler.

Return:

  • Express application

Kamboja.use

Register a middleware to the KambojaJS application. You are free to assign KambojaJS middleware or Express middleware

Parameters:

  • middleware <string> or function or Core.Middleware If provided string middleware will be resolved using qualified class name. If provide function it assume that the assigned parameter was a Express middleware.
import { KambojaApplication } from "kamboja-express"
import * as BodyParser from "body-parser"

let app = new KambojaApplication(__dirname)
    .use(BodyParser.json())
    .init()

app.listen(5000)

Kamboja.set

Set KambojaJS configuration described in KambojaOption, and also call the Express set internally

import { KambojaApplication } from "kamboja-express"
import * as Path from "path"

let app = new KambojaApplication(__dirname)
    //express configuration is supported
    .set("views", Path.join(__dirname, "view"))
    .set("view engine", "pug")
    //KambojaJS configuration also can be set
    .set("controllerPaths", ["controller", "api"])
    .set("showLog", "Error")
    .init()
app.listen(5000)

Kamboja.get

Retrieve KambojaJS configuration described in KambojaOption. Please note you can’t get Express configuration using get. This method usually used in Facility to get current configuration.

Kamboja.apply

Apply Facility to the KambojaJS system.

Parameters:

  • facility <string> or <Facility> instance.
import { KambojaApplication } from "kamboja-express"
import { MongooseFacility } from "kamboja-mongoose"

let app = new KambojaApplication(__dirname)
    .apply(new MongooseFacility())
    .init()
    
app.listen(5000)