• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript express-handlebars.default函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中express-handlebars.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

let initialize = function(app){

    app.set("views", config.root + "/server/views");

    app.engine(".hbs", exphbs({
        defaultLayout: "main",
        extname: ".hbs",
        // in the feature we probably don"t need the next 2 lines
        // https://github.com/ericf/express-handlebars/issues/147#issuecomment-159737839
        layoutsDir: config.root + "/server/views/layouts/",
        partialsDir: config.root + "/server/views/partials/",

        // ensure the javascript is at the bottom of the code in express-handlebars template
        // http://stackoverflow.com/a/25307270
        // helpers: {
        //     section: function(name, options){
        //         if (!this._sections) { this._sections = {}; };
        //         this._sections[name] = options.fn(this);
        //         return null;
        //     }
        // }
    }));

    app.set("view engine", ".hbs");

    if (config.env === "production" || config.env === "staging") {
        // app.use(favicon(path.join(config.root, "client", "favicon.ico")));

        // app.use(express.static(path.join(config.root, "client"), { index: "_" }));

        // // app.use(morgan("tiny", { // like "dev" but no colors
        // //     //skip: function(req, res) { return res.statusCode < 400 },
        // //     stream: logger.stream }));

    } else { // development
        // // app.use(favicon(path.join(config.root, "client", "favicon.ico")));

        // // if you are happy with a browser plugin, then you don"t need this middleware
        // // live-reload corrupts pdf files: http://stackoverflow.com/a/28091651/2726725
        // app.use(require("connect-livereload")({
        //     port: 35729, // default=35729
        //     ignore: [/print/]  // all that contains "print": https://github.com/intesso/connect-livereload#options
        // }));

        // without last argument express serves index.html even when my routing is to a different file:
        // http://stackoverflow.com/a/25167332/2726725
        // It is also recommended to put static middleware first: http://stackoverflow.com/a/28143812/2726725
        // Have this pb. only when I try to serve another jade page as homepage
        app.use("/", express.static(path.join(config.root, "client"), { index: "_"} ));
        app.use("/node_modules", express.static(path.join(config.root, "node_modules"))); // to serve node_modules

        // app.use(morgan("dev", { stream: logger.stream }));
        // app.use(morgan("dev"));
    }

    // add a second static source for static files:
    // http://stackoverflow.com/questions/5973432/setting-up-two-different-static-directories-in-node-js-express-framework
    app.use("/public", express.static(path.join(config.root, "server/public")));

    // for js files used by some views
    app.use("/views", express.static(path.join(config.root, "server/views")));

    allRoutes(app);
    return app;
};
开发者ID:lmaran,项目名称:logspace,代码行数:65,代码来源:initialize.ts


示例2: exphbs

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(methodOverride("_method"));
app.use(methodOverride("X-HTTP-Method-Override"));
app.use(favicon(__dirname + "/public/favicon.ico"));
app.use("/bower_components", express.static(__dirname + "/bower_components"));

//Routes
app.use('/api/v1', apiRoutes.getRoutes(app, express.Router()));
app.use("/", webroutes.getRoutes(app, express.Router()));

//File Paths
app.set('views', path.join(__dirname, 'views'));
app.engine('.hbs', exphbs({defaultLayout: 'main', extname: '.hbs'}));
app.set('view engine', '.hbs');
app.use(express.static(path.join(__dirname, "public")));


passportConfig.ConfigurePassport(app);

/**************************************/
/*      Logs                          */
/**************************************/
// create a write stream (in append mode)
var logStream = fs.createWriteStream(__dirname + '/morganLog.log', { flags: 'a' })
// You can set morgan to log differently depending on your environment
if (app.get('env') == 'production') {
    app.use(morgan('common', {
        skip: function (req, res) {
开发者ID:jahmaiosullivan,项目名称:hopabode,代码行数:31,代码来源:server.ts


示例3: require

(() => {
	"use strict";

	const path = require("path");
	let config = require('../config/config.json');
	config.serverRoot = path.join(__dirname, '../');
	const routes = require(config.serverRoot + 'config/routes.json');
	const fs = require("fs");
	const http = require('http');
	const https = require('https');
	const bodyParser = require('body-parser')
	const express = require('express');
	const exphbs = require('express-handlebars');
	const app = express();


	//set view engine
	if (config.handlebarsTemplateEngine) {
		app.set('views', config.serverRoot + '/views');
		
		const exphbsOptions = {
			defaultLayout: 'main',
			layoutsDir: config.serverRoot + '/views/layouts',
			partialsDir: config.serverRoot + '/views/partials',
			extname: ".view.html"
		};

		app.engine('.view.html', exphbs(exphbsOptions));
		app.set('view engine', '.view.html');
		app.enable('view cache');
	}

	//setting the static folder fo the app
	app.use(express.static(path.join(config.serverRoot, '../src/public')));


	//routing
	//loop through the routes.json file
	//connecting the right controller 
	//for each route and create it
	routes.forEach((route) => {
		const controller = require(config.serverRoot + '/controllers/' + route.controller + '.ctrl');
		let middlewares = [];

		//load middlewares if exist for this route
		if (typeof route.middlewares !== "undefined" && route.middlewares.length) {
			route.middlewares.forEach((midName) => {
				const m = require(config.serverRoot + '/middlewares/' + midName + '.mid.ts');
				middlewares.push(m);
			});
		}

		app.all(route.path, middlewares, controller);
	});


	//reducing the http header size 
	//by removing x-powered-by
	app.disable('x-powered-by');


	//set the http server
	if (config.httpServer) {
		const httpServer = http.createServer(app);
		httpServer.listen(config.httpPort, () => {
			console.log(`${config.appName} http server listening on port ${config.httpPort}`);
		});
	}


	//set the https server
	if (config.httpsServer) {
		const sslConfig = {
			key: fs.readFileSync(config.serverRoot + 'config/ssl/file.pem'),
			cert: fs.readFileSync(config.serverRoot + 'config/ssl/file.crt')
		};

		const httpsServer = https.createServer(sslConfig, app);

		httpsServer.listen(config.httpsPort, () => {
			console.log(`${config.appName} https server listening on port ${config.httpsPort}`);
		});
	}
})();
开发者ID:spear4life,项目名称:Socotra,代码行数:84,代码来源:main.ts


示例4: require

import * as express from "express";
import * as path from "path";
var expressHandlebars = require("express-handlebars");

import index from "./controllers/index";

const app: express.Express = express();

app.engine("handlebars", expressHandlebars({defaultLayout: "main"}));
app.set("view engine", "handlebars");

app.use(express.static(path.join(__dirname, "public")));

app.use("/", index);

if (app.get("env") === "development") {
    app.use((error: any, req, res, next) => {
        res.status(error["status"] || 500);
        res.render("error", {
            message: error.message,
            error
        });
    });
};

app.use((error: any, req, res, next) => {
    res.status(error["status"] || 500);
    res.render("error", {
        message: error.message,
        error: {}
    });
开发者ID:EliotJones,项目名称:eliot-jones-node,代码行数:31,代码来源:app.ts


示例5: require

'use strict';

import express = require('express');
import path = require('path');
import _ = require('lodash');

const config = require('../app-config');
const app = express();

// let favicon = require('serve-favicon');
// app.use(favicon(__dirname + '/../client/favicon.ico'));

var hbs = require('express-handlebars');
app.engine('handlebars', hbs());
app.set('view engine', 'handlebars');
app.set('views', 'server/views/');

app.use('/systemjs.config.js', express.static(path.resolve(__dirname, '../systemjs.config.js')));
app.use('/client', express.static(path.resolve(__dirname, '../client')));
app.use('/node_modules', express.static(path.resolve(__dirname, '../node_modules')));

const bodyParser = require('body-parser');
app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: true }));

const arangojs = require('arangojs');
const username = config.arangodb.username;
const password = config.arangodb.password;
const url = `http://${username}:${password}@localhost:8529`;
const db = arangojs({ url, databaseName: 'think' });
开发者ID:andregs,项目名称:think-before-voting,代码行数:30,代码来源:server.ts



注:本文中的express-handlebars.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript express-jwt.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript express-handlebars.create函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap