-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (60 loc) · 2.34 KB
/
Copy pathapp.js
File metadata and controls
66 lines (60 loc) · 2.34 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require("express");
const path = require("path");
const { formattedDate } = require("./transformer");
const RF = require("./services/rainfocus");
const DA = require("./services/da");
const HLX = require("./services/hlx");
const autoUpdateContent = require("./utils/content-update");
const { JSDOM } = require("jsdom");
require("dotenv").config();
const app = express();
const PORT = 5001;
// Serve static files (optional)
app.use(express.static(path.join(__dirname, "public")));
// Route to render template
app.get("/", async (req, res) => {
//Fetch session template from DA
const daUrl = "https://admin.da.live/source";
const daOrg = "adobecom";
const daPath = "/da-bacom/drafts/sharmeeb/t1-events/sample-template.html";
const daToken = process.env.DA_TOKEN;
const DAService = new DA(daUrl, daOrg, daPath, daToken);
const daHTML = await DAService.fetchDoc();
console.log("DA Document:", daHTML);
if (!daHTML) {
return res.status(500).send("Error fetching data from DA");
}
// Fetch data from Rainfocus for a single session
const apiProfileId = process.env.API_PROFILE_ID;
const sessionId = process.env.SESSION_ID;
const RFService = new RF(apiProfileId, sessionId);
const payload = await RFService.fetchDoc();
console.log("Payload from Rainfocus:", payload);
if (!payload) {
return res.status(500).send("Error fetching data from Rainfocus");
}
const finalPayload = {
eventName: payload.data[0].eventName,
abstract: payload.data[0].abstract,
participants: payload.data[0].participants,
...payload,
};
// Render the template with the payload
const dom = new JSDOM(daHTML);
const updatedDOM = autoUpdateContent(dom.window.document, finalPayload);
// TODO: Publish to EDS
// const hlxUrl = "https://admin.hlx.page/preview";
// const hlxOrg = "adobecom";
// const hlxPath = "/da-bacom/main/drafts/sharmeeb/t1-events/sample-event";
// const hlxToken = process.env.HLX_TOKEN;
// const HLXService = new HLX(hlxUrl, hlxOrg, hlxPath, hlxToken);
// const hlxRes = await HLXService.preview();
// console.log("HLX Document:", hlxHTML);
// if (!hlxHTML) {
// return res.status(500).send("Error fetching data from HLX");
// }
res.send(updatedDOM.documentElement.outerHTML);
});
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});