You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.2 KiB

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;
},
};
}