-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptHandler_node.js
More file actions
26 lines (22 loc) · 1.08 KB
/
ScriptHandler_node.js
File metadata and controls
26 lines (22 loc) · 1.08 KB
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
//Node JS Code that will take the html template as input and output a precompiled js function from nunjucks
//
const nunjucks = require('nunjucks');
const express = require('express');
const app = express();
//need to use the bodyparser node module to get POST variables...
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({extended:true}));
const port = 3033; //ports 2999 - 3032 are reserved for the styleAssembler app
app.post('/templateCompiler/', function (req, res) {
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
console.log(nunjucks);
let body = req.body;
let name = body.name.toString();
let template = body.template;
let precompiled = nunjucks.precompileString(template, {name:req.body.name});
//res.send(req.param);
res.send({template:template, precompiled:precompiled});
});
app.listen(port, () => console.log(`listening on port ${port}`));