forked from Saxonica/helloWorldNodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 1.1 KB
/
index.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
const express = require('express');
const cors = require('cors');
const dotenv = require('dotenv').config();
const SaxonJS = require('saxon-js');
const stylesheet = require('./main.sef.json');
const app = express();
const homepage = (request, response) => {
const options = { "stylesheetInternal": stylesheet,
"destination": "serialized" };
SaxonJS.transform(options, "async")
.then(output => {
response.status(200).send(output.principalResult);
}).catch(error => {
response.status(400).send(error);
});
};
const jsonpage = (request, response) => {
const options = { "stylesheetInternal": stylesheet,
"stylesheetParams": { "payload": { "hello": "world" } },
"destination": "serialized" };
SaxonJS.transform(options, "async")
.then(output => {
response.status(200).send(output.principalResult);
}).catch(error => {
response.status(400).send(error);
});
};
app.use(cors());
app.route("/").get(homepage);
app.route("/json").get(jsonpage);
// Start server
app.listen(process.env.PORT, () => {
console.log(`Server listening`);
});