-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtime.js
42 lines (35 loc) · 1.07 KB
/
runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require("marko/compiler").configure({ writeToDisk: false });
const arc = require("@architect/functions");
const getDefaultBuildConfig = require("./getDefaultBuildConfig");
function route(template, data, onDone, onError) {
return function(req, res) {
let renderPromise = template // eslint-disable-line no-unused-vars
.render(data)
.then(out => res({ html: out.getOutput() }));
if (onDone) {
renderPromise = renderPromise.then(onDone);
}
renderPromise = renderPromise.catch(
onError ||
function(err) {
console.error("Error rendering template: ", err);
res({ status: 500 });
}
);
};
}
let lassoConfigured = false;
exports.run = function({ template, buildConfig, data, onDone, onError }) {
if (!lassoConfigured) {
const config = Object.assign(
{},
buildConfig || getDefaultBuildConfig(process.cwd()),
{
loadPrebuild: true
}
);
require("lasso").configure(config);
lassoConfigured = true;
}
return arc.html.get(route(template, data, onDone, onError));
};