How to use the pug.__express function in pug

To help you get started, we’ve selected a few pug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blockstream / esplora / prerender-server / src / server.js View on Github external
import l10n from '../client/l10n'
import render from '../client/run-server'

const themes = [ 'light', 'dark' ]
    , langs = Object.keys(l10n)
    , baseHref = process.env.BASE_HREF || '/'
    , canonBase = process.env.CANONICAL_URL ? process.env.CANONICAL_URL.replace(/\/$/, '') : null
    , apiUrl = process.env.API_URL.replace(/\/$/, '')

const rpath = p => path.join(__dirname, p)

const indexView = rpath('../../client/index.pug')

const app = express()
app.engine('pug', pug.__express)

if (app.settings.env == 'development')
  app.use(require('morgan')('dev'))

app.use(require('cookie-parser')())
app.use(require('body-parser').urlencoded({ extended: false }))

app.use((req, res, next) => {
  // TODO: optimize /block-height/nnn (no need to render the whole app just to get the redirect)

  let theme = req.query.theme || req.cookies.theme || 'dark'
  if (!themes.includes(theme)) theme = 'light'
  if (req.query.theme && req.cookies.theme !== theme) res.cookie('theme', theme)

  let lang = req.query.lang || req.cookies.lang || 'en'
  if (!langs.includes(lang)) lang = 'en'
github gnodi / danf / lib / server / framework / initializer.js View on Github external
Initializer.prototype.process = function(framework, parameters, danf, configuration) {
    var app = framework.get('danf:app'),
        config = parameters['config']
    ;

    // Initialize the rendering.
    var pug = require('pug').__express;
    app.set('view engine', pug);
    app.engine('pug', pug);
    app.engine('jade', pug);

    // Define assets.
    if ('test' !== app.context.environment) {
        var mapper = framework.get('danf:assets.mapper'),
            assetsConfigRegistry = framework.get('danf:configuration.registry.assets')
        ;

        assetsConfigRegistry.addObserver(mapper);
        assetsConfigRegistry.registerSet(danf.assets);
        assetsConfigRegistry.registerSet(config.assets || {});

        app.use(defineStatic(mapper, parameters.context));
    }
}
github openmrs / openmrs-contrib-id / app / app.js View on Github external
exports = module.exports = app;

// patch log4js
require('./logger');
const log4js = require('log4js');

// connect to mongo
require('./new-db');


const mid = require('./express-middleware');
const conf = require('./conf');
const log = log4js.addLogger('express');

const siteURLParsed = url.parse(conf.site.url, false, true);
app.engine('pug', engine);
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, '/../templates'));
app.locals._ = _;
app.set('basepath', siteURLParsed.pathname);
app.set('port', 3000);
app.use(flash());
app.use(bodyParser.urlencoded({
  extended: false
}));
app.use(bodyParser.json());
app.use(cookieParser());


// store express session in MongoDB
const sessionStore = new MongoStore({
  url: conf.mongo.uri,
github gnodi / danf / lib / server / framework / initializer.js View on Github external
Initializer.prototype.process = function(framework, parameters, danf, configuration) {
    var app = framework.get('danf:app'),
        config = parameters['config']
    ;

    // Initialize the rendering.
    var pug = require('pug').__express;
    app.set('view engine', pug);
    app.engine('pug', pug);
    app.engine('jade', pug);

    // Define assets.
    if ('test' !== app.context.environment) {
        var mapper = framework.get('danf:assets.mapper'),
            assetsConfigRegistry = framework.get('danf:configuration.registry.assets')
        ;

        assetsConfigRegistry.addObserver(mapper);
        assetsConfigRegistry.registerSet(danf.assets);
        assetsConfigRegistry.registerSet(config.assets || {});

        app.use(defineStatic(mapper, parameters.context));
    }
}
github Blockstream / esplora / dev-server.js View on Github external
import fs from 'fs'
import pug from 'pug'
import path from 'path'
import express from 'express'
import browserify from 'browserify-middleware'
import cssjanus from 'cssjanus'

const rpath = p => path.join(__dirname, p)

const app = express()

app.engine('pug', pug.__express)

app.use(require('morgan')('dev'))

if (process.env.CORS_ALLOW) {
  app.use((req, res, next) => {
    res.set('Access-Control-Allow-Origin', process.env.CORS_ALLOW)
    next()
  })
}

if (process.env.PRERENDER_URL) {
  app.use((req, res, next) => {
    if (req.query.nojs != null) return res.redirect(303, process.env.PRERENDER_URL+req.path)
    next()
  })
}