當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。