import express from "express"; import bodyParser from "body-parser"; import {createServer} from "http"; import {create} from "express-handlebars"; import {escape} from "lodash-es"; import {sanitizeUrl} from "@braintree/sanitize-url"; import path from "path"; export function init() { const app = express(); // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({extended: false})); // parse application/json app.use(bodyParser.json()); const hbs = getHandlebarsViewEngine(); app.engine('.hbs', hbs.engine); app.set('view engine', '.hbs'); const modulesPath = '.'; app.set('views', path.join(modulesPath, 'layouts')); // Static Files of blockDevTool. app.use(express.static(path.join(modulesPath, 'layouts'))); return { expressApp: app, httpServer: createServer(app), }; } function getHandlebarsViewEngine() { return create({ extname: '.hbs', defaultLayout: false, partialsDir: ['.'], helpers: handlebarsHelpers() }); } function handlebarsHelpers() { return { esc_attr(attr) { return escape(attr); }, esc_url(url) { return sanitizeUrl(url); }, esc_html(html) { return html; }, }; }