This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
podlet.js
63 lines (50 loc) · 1.92 KB
/
podlet.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const Podlet = require("@podium/podlet");
const fs = require("fs");
const basePath = process.env.BASE_PATH || "/person/podlet-dittnav-personalia";
const port = process.env.PORT || 7300;
const podletVersion = process.env.VERSION_HASH || `${new Date().getTime()}`;
const isDevelopmentEnv = true;
const podletName = "podlet-dittnav-personalia";
let rawdata = fs.readFileSync("build/asset-manifest.json");
let assets = JSON.parse(rawdata);
const app = express();
const podlet = new Podlet({
name: podletName,
version: podletVersion,
pathname: "/",
fallback: "/fallback",
content: "/",
development: isDevelopmentEnv,
logger: console,
});
assets.entrypoints.forEach((element, index) => {
if (element.indexOf(".css") !== -1) {
podlet.css({ value: `/${element}` });
} else if (element.indexOf(".js") !== -1) {
podlet.js({ value: `/${element}`, defer: true });
}
});
app.use(podlet.middleware());
app.use("/static", express.static("./build/static"));
app.use("/assets", express.static("./build/"));
app.use(`${basePath}/static`, express.static("./build/static"));
app.use(`${basePath}/assets`, express.static("./build/"));
app.get(`${basePath}${podlet.content()}`, (req, res) => {
res.status(200).podiumSend(`<div id="${podletName}"></div>`);
});
app.get(`${basePath}${podlet.fallback()}`, (req, res) => {
res.status(200).podiumSend(`<div>Fallback for ${podletName}:${podletVersion}</div>`);
});
// generate the podlet manifest
app.get(`${basePath}${podlet.manifest()}`, (req, res) => {
res.status(200).send(podlet);
});
// isAlive/isReady route for Nais
app.get(`${basePath}/isAlive|isReady`, (req, res) => res.sendStatus(200));
//start the app at port
console.log(JSON.stringify(podlet, undefined, 2));
console.log(`Content path ${podlet.content()}`);
console.log(`Manifest path ${podlet.manifest()}`);
console.log(`Starting on port ${port} with basePath ${basePath}`);
app.listen(port);