Skip to content

Instantly share code, notes, and snippets.

@bjerkek
Created May 4, 2021 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjerkek/fbf7f28c8de1bf1edff7b033e6c06de1 to your computer and use it in GitHub Desktop.
Save bjerkek/fbf7f28c8de1bf1edff7b033e6c06de1 to your computer and use it in GitHub Desktop.
Learning Podium - My loans podlet 2
const express = require('express');
const Podlet = require('@podium/podlet');
const fs = require('fs');
const app = express();
const domain = 'http://localhost';
const port = '7300';
const url = `${domain}:${port}`;
const podlet = new Podlet({
name: 'my-loans',
version: '1.0.0',
pathname: '/',
manifest: '/manifest.json',
content: '/',
fallback: '/fallback',
development: true,
});
app.use(podlet.middleware());
app.get(podlet.content(), (req, res) => {
res.status(200).podiumSend(`
<div id="myLoansPodletRoot"></div>
`);
});
app.get(podlet.manifest(), (req, res) => {
res.status(200).send(podlet);
});
app.use('/assets', express.static('build/static'));
const reactAssetManifest = fs.readFileSync("build/asset-manifest.json");
const assets = JSON.parse(reactAssetManifest);
assets.entrypoints.forEach(element => {
const filename = element.replace('static', `${url}/assets`);
if (element.includes('.css')) {
podlet.css({ value: filename });
}
if (element.includes('.js')) {
podlet.js({ value: filename });
}
});
app.listen(port, () => {
console.log(url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment