Launching web-app
These page summarizes basic concepts of running a Mandarine-powered web application.
Last updated
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.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.tsGET /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