本文整理匯總了TypeScript中express-handlebars.create函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript create函數的具體用法?TypeScript create怎麽用?TypeScript create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了create函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor() {
/**
* instantiate App
*/
this._app = express();
this._app.enable('trust proxy');
const hbs = handlebars.create({ defaultLayout: "main" });
/**
* configure bodyParser and handlebars
*/
this._app.use(bodyParser.json());
this._app.use("/", router);
this._app.use(bodyParser.json());
this._app.use(bodyParser.urlencoded({extended: false}));
this._app.set("port", (process.env.PORT || 8080));
this._app.engine("handlebars", hbs.engine);
this._app.set("view engine", "handlebars");
}
示例2: function
export default function(app) {
var hbs = exphbs.create({
defaultLayout: 'layout',
helpers: {
json: function(object) {
return object ? JSON.stringify(object) : "null";
},
section: function(name, options) {
if (!this._sections) {
this._sections = {};
}
this._sections[name] = options.fn(this);
return null;
},
console: function(object) {
console.log(object);
},
typeof: function(object) {
return typeof object;
},
keys: function(object) {
return Object.keys(object);
},
iftext: function(object, ifTrue, ifFalse) {
if (object) {
return ifTrue;
} else {
return ifFalse;
}
}
}
});
app.engine(hbs.extname, hbs.engine);
app.set('view engine', hbs.extname);
return hbs;
};
示例3: createHandlebars
private createHandlebars (): Exphbs {
return exphbs.create({
defaultLayout: "main",
helpers: templateHelpers,
});
}
示例4: Config
import { HomeController } from './controllers/home.controller';
import { Router } from './router';
import { Config } from './config';
var config = new Config();
var homeController = new HomeController();
var app = express();
app.use(express.static('public'));
// use router
app.use('/', new Router().router);
// use cookie and session
app.use(cookieParser(config.session_secret));
app.use(session({
secret: config.session_secret,
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
//register view engine
app.engine('html', handlebars.create({ defaultLayout: "main", extname: '.html' }).engine);
app.set('view engine', 'html');
// bodyParser
app.use(bodyParser.json({ limit: '1mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '1mb' }));
app.get('/', homeController.index);
app.listen(config.port, function () {
console.log(`Example app listening on port ${config.port}!`);
});
示例5: express
import * as express from 'express';
import * as path from 'path';
import * as ExpressHandlebars from 'express-handlebars';
import * as bodyParser from 'body-parser';
import * as multer from 'multer';
import './db';
import './models';
import { productController } from './controllers/product';
import { searchController } from './controllers/search';
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
app.get('/', function(req, res) {
res.send("hello world");
});
productController.registerRoutes(app);
searchController.registerRoutes(app);
// set handlebars as view engine
const handlebars = ExpressHandlebars.create({ defaultLayout: 'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
const server = app.listen(8080);
示例6: require
import * as core from "express-serve-static-core";
import path = require("path");
import bodyParser = require("body-parser");
import fs = require("fs");
var exphbs = require('express-handlebars');
import favicon = require("serve-favicon");
import logger = require("morgan");
import cookieParser = require("cookie-parser");
import helmet = require("helmet");
import compression = require("compression");
var routes = require('./routes/index');
var users = require('./routes/users');
var app: core.Express = express();
var hbs = exphbs.create();
importTemplates(projetRacine + "views/template", hbs.handlebars);
if (app.get('env') !== 'development') {
app.use(helmet())
app.use(compression());
app.enable('view cache');
}else{
app.use(logger('dev'));
}
// view engine setup
app.set('views', path.join(projetRacine, 'views'));
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
示例7: express
// let appInsights = require("applicationinsights");
// let instrumentationKey = config.get("app.instrumentationKey");
// if (instrumentationKey) {
// appInsights.setup(instrumentationKey).start();
// }
let app = express();
app.set("port", process.env.PORT || 3978);
app.use(express.static(path.join(__dirname, "../../public")));
app.use(express.static(path.join(__dirname, "./public"))); // used for static dialogs
app.use(favicon(path.join(__dirname, "../../public/assets", "favicon.ico")));
let handlebars = exphbs.create({
extname: ".hbs",
helpers: {
appId: () => { return config.get("app.appId"); },
},
});
app.engine("hbs", handlebars.engine);
app.set("view engine", "hbs");
// Tab and Popup urls
app.get("/loading", LoadingTab.getRequestHandler());
app.get("/default", DefaultTab.getRequestHandler());
app.get("/allCommands", AllCommandsTab.getRequestHandler());
app.get("/vstsAuth", VSTSAuthTab.getRequestHandler());
app.get("/vstsAuthFlowStart", VSTSAuthFlowStartPopUp.getRequestHandler());
app.get("/vstsAuthFlowEnd", VSTSAuthFlowEndPopUp.getRequestHandler());
app.get("/composeExtensionSettings", ComposeExtensionSettingsPopUp.getRequestHandler());
// Tab authentication sample routes
示例8: express
import * as providers from "./providers";
import * as storage from "./storage";
import { AuthBot } from "./AuthBot";
import { logger } from "./utils/index";
let app = express();
let appId = config.get("app.appId");
app.set("port", process.env.PORT || 3978);
app.use(express.static(path.join(__dirname, "../../public")));
app.use(favicon(path.join(__dirname, "../../public/assets", "favicon.ico")));
app.use(bodyParser.json());
let handlebars = exphbs.create({
extname: ".hbs",
helpers: {
appId: () => { return appId; },
},
});
app.engine("hbs", handlebars.engine);
app.set("view engine", "hbs");
// Configure storage
let botStorageProvider = config.get("storage");
let botStorage = null;
switch (botStorageProvider) {
case "mongoDb":
botStorage = new storage.MongoDbBotStorage(config.get("mongoDb.botStateCollection"), config.get("mongoDb.connectionString"));
break;
case "memory":
botStorage = new storage.MemoryBotStorage();
break;
示例9: express
/// <reference path="../typings/index.d.ts" />
import * as express from "express";
import * as hbs from "express-handlebars";
import * as path from "path";
import Config from "../config/config";
import * as apiRoute from "./api/router";
var app = express();
app.engine('html', hbs.create({extname: '.html', layoutsDir: __dirname + '../src/'}).engine);
app.set('views',path.join(__dirname,'../src/'));
app.set('view engine', 'html');
app.use('/', function (req, res, next) {
var hostname = req.headers['host'].split(":")[0].split('.');
if (hostname.length <= 3) {
if (Config.subDomains.indexOf(hostname[0]) > -1) {
app.use('/', apiRoute);
}
}
next();
});
app.use('/', function (req, res,next) {
if(Config.pages.indexOf(req.url.substr(1)) > -1 ){
res.render('index',{
scripts:Config.scripts