当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript express-handlebars类代码示例

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


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

示例1: create

export async function create() {
    var app: express.Express = express();

    // TODO: move to new express typings.  blocked by res.send(obj); file issue
    //var app: express.Application = express();

    // app.set('views', path.join(__dirname, 'views'));
    // app.set('view engine', 'hjs');

    app.engine('handlebars', exphbs({defaultLayout: 'main'}));
    app.set('view engine', 'handlebars');    

    // TODO: hook up logger

    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(cookieParser());
    app.use(express.static(path.join(__dirname, 'public')));

    // -------------------------------------------------------
    // routes
    // -------------------------------------------------------
    await routes.setup(app);

    // -------------------------------------------------------
    // error handling
    // -------------------------------------------------------

    // forward routes not found to the error handler
    app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
        let err = new Error('Not Found');
        err['status'] = 404;
        next(err);
    });

    // development error handler
    // will print stacktrace
    if (app.get('env') === 'development') {
        app.use((err, req: express.Request, res: express.Response, next: express.NextFunction) => {
            res.status(err.status || 500);
            res.render('error', {
                message: err.message,
                error: err
            });
        });
    }

    // production error handler
    // no stacktraces leaked to user
    app.use((err, req: express.Request, res: express.Response, next: express.NextFunction) => {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: {}
        });
    });    

    return app;
}
开发者ID:bryanmacfarlane,项目名称:sanenode,代码行数:59,代码来源:app.ts

示例2: Express

    .then((): httpServer | null => {

      const app: Express.Application = Express();
      app.engine("handlebars", exphbs({defaultLayout: "main"}));
      app.set("view engine", "handlebars");

      const router: Express.Router = Express.Router();
      addRoutes(router);
      app.use("/", router);

      return app.listen(port);
    })
开发者ID:jw120,项目名称:fcc-url-shortener,代码行数:12,代码来源:server.ts

示例3: initRoutes

export async function initRoutes(app: Express) {
  console.log('Init routes...');

  app.set('trust proxy', 'loopback');
  app.use(compression());
  app.use(bodyParser.json());

  await db.init();
  stats.init();

  app.post('/vote', (req, res) => {
    const vote: Vote = req.body;
    if (isVoteValid(vote)) {
      stats.addVote(vote);
      db.saveVote(extend(vote, {
        date: new Date(),
        ip: req.ip,
        userAgent: req.get('User-Agent')
      })).then(oldVote => {
        if (oldVote) {
          stats.removeVote(oldVote);
        }
      });
    } else {
      console.log('Invalid vote', vote);
    }
    res.json({});
  });

  app.get('/stats', (_req, res) => {
    res.set('Cache-Control', 'max-age=' + 1);
    res.json(stats.getStats());
  });

  app.use(express.static('public'));

  app.set('views', './server/views');
  app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
  app.set('view engine', 'handlebars');

  app.get(/^\/$|\/index.html/, (req, res) => {
    renderWithClientToken('index', req, res);
  });

  app.get('/iframe.html', (req, res) => {
    renderWithClientToken('iframe', req, res);
  });

};
开发者ID:shybyte,项目名称:wahlomat,代码行数:49,代码来源:routes.ts

示例4: setupTemplating

async function setupTemplating(app: express.Application) {
  app.engine(
    '.hbs',
    exphbs({
      defaultLayout: 'main',
      extname: '.hbs',
      helpers: await loadHandlebarsHelpers()
    })
  );
  app.set('view engine', '.hbs');
  app.use((req, res, next) => {
    let { url, query } = req;
    res.locals.request = { url, query };
    next();
  });
}
开发者ID:qjac,项目名称:sql-fundamentals,代码行数:16,代码来源:express-server.ts

示例5: exphbs

var env = process.env.NODE_ENV || 'development';
app.locals.ENV = env;
app.locals.ENV_DEVELOPMENT = (env === 'development');

//ignore HTTPS errors
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

// view engine setup
app.engine('handlebars', exphbs({
  layoutsDir: settings.root + '/views/layouts/',
  defaultLayout: settings.layoutFile,
  partialsDir: [settings.root +'/views/partials/'],
  helpers: {
    scrollSpy: helpers.scrollSpy,
    siteDirectory: helpers.siteDirectory,
    breadCrumb: helpers.breadCrumb,
    dirEntry: helpers.dirEntry
  },
  compilerOptions: {
    preventIndent: true
  }
}));
app.set('views', settings.root + '/views'); 
app.set('view engine', 'handlebars');

app.use(favicon(settings.root + '/public/img/favicon.ico'));

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
开发者ID:skijit,项目名称:nodtes,代码行数:31,代码来源:app.ts

示例6: require

if (!WallTime.rules) {
  var tzData = require("chronoshift/lib/walltime/walltime-data.js");
  WallTime.init(tzData.rules, tzData.zones);
}

import { VERSION, DATA_SOURCE_MANAGER, HIDE_GITHUB_ICON, HEADER_BACKGROUND } from './config';
import * as plywoodRoutes from './routes/plywood/plywood';

var app = express();
app.disable('x-powered-by');

// view engine setup
const viewsDir = path.join(__dirname, '../../src/views');
app.engine('.hbs', handlebars({
  defaultLayout: 'main',
  extname: '.hbs',
  layoutsDir: path.join(viewsDir, 'layouts'),
  partialsDir: path.join(viewsDir, 'partials')
}));
app.set('views', viewsDir);
app.set('view engine', '.hbs');

app.use(compress());
app.use(logger('dev'));

app.use(express.static(path.join(__dirname, '../../build/public')));
app.use(express.static(path.join(__dirname, '../../assets')));

app.use(bodyParser.json());

app.get('/', (req: Request, res: Response, next: Function) => {
  DATA_SOURCE_MANAGER.getQueryableDataSources().then((dataSources) => {
开发者ID:fortressll87,项目名称:implydata-pivot,代码行数:32,代码来源:app.ts

示例7: express

import {registerBookCopiesRoutes} from "./controllers/bookCopyController";
import {LoanController} from "./controllers/loanController";

let app = express();
let api = express();
app.use("/api", api);

app.use(require("morgan")("dev"));
DbConnection.initConnection(app.get("env"));
app.engine("handlebars", handlebars({
    defaultLayout: "main",
    partialsDir: "views/partials",
    helpers: {
        section: function (name, options) {
            if (!this._sections) {
                this._sections = {};
            }
            this._sections[name] = options.fn(this);
            return null;
        }
    }
}));
app.set("view engine", "handlebars");
app.set("port", process.env.PORT || 5000);
app.use(cookieParser(credentials.cookieSecret));
app.use(expressSession());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

//TODO.md: domains are deprecated and will be removed in the future,
//find an alternative
开发者ID:JohanBaskovec,项目名称:nodejslibrary,代码行数:31,代码来源:server.ts


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