1 | import { Request as ERequest, Response as EResponse } from "express";
|
2 | import Response from "./response";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export default class RenderResponse extends Response {
|
8 | private view: string;
|
9 | private context: any;
|
10 |
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 | constructor(view: string, context: any) {
|
17 | super();
|
18 | this.view = view;
|
19 | this.context = context;
|
20 | }
|
21 |
|
22 | performResponse(req: ERequest, res: EResponse) {
|
23 | if (!this.context) {
|
24 | this.context = {};
|
25 | }
|
26 | if ((req as any).lang) {
|
27 | this.context.lang = (req as any).lang;
|
28 | } else {
|
29 | this.context.lang = "it";
|
30 | }
|
31 | res.render(this.view, this.context);
|
32 | }
|
33 | }
|