Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var config = require("config");
var Express = require("express");
var brochure = new Express();
var hbs = require("hbs");
var Cache = require("express-disk-cache");
var cache = new Cache(config.cache_directory);
var warmCache = require('./warmCache');
// Configure the template engine for the brochure site
hbs.registerPartials(__dirname + "/views/partials");
brochure.set("views", __dirname + "/views");
brochure.set("view engine", "html");
brochure.engine("html", hbs.__express);
if (config.cache === false) {
// During development we want views to reload as we edit
brochure.disable("view cache");
} else {
// This will store responses to disk for NGINX to serve
brochure.use(cache);
// Empty any existing responses
cache.flush(config.host, function(err) {
if (err) console.warn(err);
warmCache(config.protocol + config.host, function(err){
if (err) console.warn(err);
public registerPage(page: any) {
var viewsPath = path.join(page.getPath(), '/views');
this.expressViews.push(viewsPath);
this.express.set('views', this.expressViews);
hbs.registerPartials(viewsPath);
this.express.use('/stylesheets', express.static(path.join(page.getPath(), 'stylesheets')));
this.express.use('/assets', express.static(path.join(page.getPath(), 'stylesheets')));
if (this.USE_SCSS) {
this.express.use(sassMiddleware({
src: path.join(page.getPath(), 'stylesheets'),
dest: path.join(page.getPath(), 'stylesheets'),
indentedSyntax: false, // true = .sass and false = .scss
sourceMap: true
}));
}
}
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var uuid = require('uuid');
var flash = require("connect-flash");
var session = require("express-session");
//environment
var environment = new require('./apps/environment')();
var app = express();
var hbs = require('hbs');
var viewPath = path.join(process.cwd(), "views");
app.set("view engine", "hbs");
app.set("views", viewPath); //path.join(__dirname, "/views"));
hbs.registerPartials(__dirname + '/views/partials');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
//app.use(cookieParser()); // collides with session
app.use(express.static(path.join(__dirname, "public")));
app.use(flash());
app.use(session({
genid: function(req) {
return uuid.v4(); // use UUIDs for session IDs
},
// builtin
var fs = require('fs');
// 3rd party
var express = require('express');
var hbs = require('hbs');
var app = express();
hbs.registerPartial('partial', fs.readFileSync(__dirname + '/views/partial.hbs', 'utf8'));
hbs.registerPartials(__dirname + '/views/partials');
// set the view engine to use handlebars
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.locals = {
some_value: 'foo bar',
list: ['cat', 'dog']
}
res.render('index');
});
use(obj){
//console.log(obj)
//return;
let self = this.proto;
let _obj = obj || {};
let viewPath = _obj.viewPath || '';
let adminViewPath = _obj.adminViewPath || '';
if(viewPath !=='')
hbs.registerPartials(viewPath);//注册前台后台视图路径
if(adminViewPath !== '')
hbs.registerPartials(adminViewPath);//注册后台模版路径
//console.log(_obj.exname)
self.exname = _obj.exname || '.hbs'; //设置模版文件后缀
//self.viewPath = viewPath;
//self.adminViewPath = adminViewPath;
return self
};
use(obj){
//console.log(obj)
//return;
let self = this.proto;
let _obj = obj || {};
let viewPath = _obj.viewPath || '';
let adminViewPath = _obj.adminViewPath || '';
if(viewPath !=='')
hbs.registerPartials(viewPath);//注册前台后台视图路径
if(adminViewPath !== '')
hbs.registerPartials(adminViewPath);//注册后台模版路径
//console.log(_obj.exname)
self.exname = _obj.exname || '.hbs'; //设置模版文件后缀
//self.viewPath = viewPath;
//self.adminViewPath = adminViewPath;
return self
};
var fs = require('fs'),
path = require('path'),
hbs = require('hbs'),
cfg = require('./config'),
helpersDir = path.normalize(__dirname + '../../helpers/');
hbs.registerPartials(cfg.micro.base_path + cfg.micro.view_partials_directory);
var files = fs.readdirSync(helpersDir);
files.forEach(function(file) {
var name = path.basename(helpersDir + file, '.js');
hbs.registerHelper(name, require(helpersDir + file));
});
module.exports = hbs;
function setup(req,res,next){
var hbs = require('hbs');
hbs.registerPartials(__dirname + '/../views/partials');
hbs.registerHelper('json', function(obj) {return JSON.stringify(obj,undefined,2); });
next();
}