# Launching web-app

## 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.

```typescript
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](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-core/properties#setting-your-own-properties), those statements must be above `new MandarineCore().MVC().run()` .&#x20;

### Run options

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

Ex.

```typescript
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.&#x20;

## 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*](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-core/core-initialization), which is just a structure where your will import all your modules in order to make mandarine compile them.

[Click here](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-core/core-initialization) to see more information about single-entry point files

{% tabs %}
{% tab title="Usage example" %}
**Files**

```typescript
service1.ts

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

@Service()
export class MyService {

    public piValue(): number {
        return 3.14;
    }

}
```

```typescript
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()}`;
    }

}
```

```typescript
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)**

```typescript
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();
```

{% endtab %}

{% tab title="Console execution" %}

```bash
deno run --config tsconfig.json --allow-net --allow-read index.ts
```

{% endtab %}

{% tab title="Result" %}

```bash
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
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mandarineframework.gitbook.io/mandarine-ts/v1.2.0/mandarine-mvc/launching-web-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
