Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Main
  • Run options
  • Single entry-point file

Was this helpful?

  1. Mandarine MVC

Launching web-app

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

PreviousAccessing data from templateNextServing Static Content

Last updated 4 years ago

Was this helpful?

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 , 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 , which is just a structure where your will import all your modules in order to make mandarine compile them.

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();
deno run --config tsconfig.json --allow-net --allow-read index.ts
GET /first-endpoint HTTP/1.1
Host: 127.0.0.1:8080

# Hello world from MyController1. <br> The value of PI is 3.14

##

GET /second-endpoint HTTP/1.1
Host: 127.0.0.1:8080

# Hello world from MyController2
setting your own configuration
mandarine single entry-point file
Click here