Launching web-app

These page summarizes basic concepts of running a Mandarine-powered web application.

Main

A Mandarine-powered web application uses all the different core across Mandarine.TS, making your application rich in functionalities. In order to run your mandarine-powered web app, you must locate the following code at the end of your file.

import { ..., MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";

...

new MandarineCore().MVC().run();

new MandarineCore().MVC.run() should always be the last line of your file, as nothing after such statement will be executed. This is important to know since for things such as setting your own configuration, those statements must be above new MandarineCore().MVC().run() .

Run options

You can pass a port and hostname to the method run .

Ex.

new MandarineCore().MVC().run({ port: 9500, hostname: "0.0.0.0" })

Note that both port and hostname are optional, however, if they are declared, they will override the default values or the values loaded from your properties file.

Single entry-point file

Almost all web applications will have multiple files distributed across multiple folders, although, only one file can be executed at the time. In order to unify all your components, controllers, and others, into one single file, you must have a mandarine single entry-point file, which is just a structure where your will import all your modules in order to make mandarine compile them.

Click here to see more information about single-entry point files

Files

service1.ts

import { Service } from "https://deno.land/x/mandarinets/mod.ts";

@Service()
export class MyService {

    public piValue(): number {
        return 3.14;
    }

}
controller1.ts

import { Controller, GET } from "https://deno.land/x/mandarinets/mod.ts";
import { MyService } from "./service1.ts";

@Controller()
export class MyController1 {

    constructor(private readonly service: MyService) {}

    @GET('/first-endpoint')
    public httpHandler() {
        return `Hello world from MyController1. <br> The value of PI is ${this.service.piValue()}`;
    }

}
controller2.ts

import { Controller, GET } from "https://deno.land/x/mandarinets/mod.ts";

@Controller()
export class MyController2 {

    @GET('/second-endpoint')
    public httpHandler() {
        return `Hello world from MyController2`;
    }

}

Index file (Single entry-point file)

index.ts

import { MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";

import { MyController1 } from "./controller1.ts";
import { MyController2 } from "./controller2.ts";
import { MyService } from "./service1.ts";

const controllers = [MyController1, MyController2];
const services = [MyService];
const middleware = [];
const repositories = [];
const configurations = [];
const components = [];
const otherModules = [];

new MandarineCore().MVC().run();

Last updated