Всем привет! Подскажите как можно подключить doT.js к своему проекта. Информация с сайта olado.github.io/doT/index.html не помогла.
У меня есть модуль роутов:
import { NextFunction, Request, Response, Router } from "express";
import {IndexController} from "../controllers/IndexController"
import {Logger} from "../helpers/LoggerHelper";
//import fetch from 'node-fetch';
//const AWS = require('aws-sdk');
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart({ uploadDir: '/root/crypto5-zak-my/upload' });
export class MainRouter{
public static create(router: Router, server) {
Logger.broadcast("debug", "[MainRouter::create] Creating call routes.");
router.get("/", (req: Request, res: Response, next: NextFunction) => {
new IndexController().index(req, res, next);
});
router.get("/login", (req: Request, res: Response, next: NextFunction) => {
new IndexController().login(req, res, next);
});
router.post("/register", (req: Request, res: Response, next: NextFunction) => {
new IndexController().register(req, res, next);
});
router.post("/login", (req: Request, res: Response, next: NextFunction) => {
new IndexController().login(req, res, next);
});
router.get("/reset", (req: Request, res: Response, next: NextFunction) => {
new IndexController().reset(req, res, next);
});
}
}
і контролери:
import { NextFunction, Request, Response, Router } from "express";
import { BaseController } from "./BaseController";
import {CognitoHelper} from "../helpers/CognitoHelper"
import * as path from "path";
import blade = require("bladejs");
blade.set({
views: path.resolve(__dirname+'/../views/'),
caches: path.resolve(__dirname+'/../caches/')
});
//import BladeRenderer = require('laravel-blade-js').Renderer;
//let renderer = new BladeRenderer();
import dots = require("dot");
export class IndexController extends BaseController {
constructor() {
super();
//let config = {}
dots.process({ path: path.resolve(__dirname+'/../views/')})
//config.views = path.resolve(__dirname+'/../views/');
//BladeRenderer.set(config);
}
public index(req: Request, res: Response, next: NextFunction) {
this.title = "test";
var r = blade.render("/register") ;
var result = blade.render("/index" ,{title: 'qqqqqqqq', content: r} ) ;
//res.render('index');
res.send(result);
//renderer.renderAsync("/index", properties = {}, settings = {});
//res.sendFile(path.resolve(__dirname+'/../views/one_to_one.html'));
}
public login(req: Request, res: Response, next: NextFunction) {
this.title = "test";
var result = blade.render("/login") ;
res.send(result);
}
public async register(req: Request, res: Response, next: NextFunction) {
let obj = req.body;
let cognito = await new CognitoHelper().register(obj.name, obj.pass, obj.email, obj.phone);
res.send(cognito);
}
public reset(req: Request, res: Response, next: NextFunction) {
this.title = "test";
var result = blade.render("/forgot") ;
res.send(result);
}
}
Или подскажите как с помощью blade сделать layouts?