mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
feat(cli-serve): serve custom snapshots (#283)
This commit is contained in:
@@ -256,6 +256,7 @@ const Cell = forwardRef(({ corona, model, initialSnOptions, initialError, onMoun
|
||||
clonedLayout = (await state.sn.component.setSnapshotData(clonedLayout)) || clonedLayout;
|
||||
}
|
||||
return {
|
||||
// TODO - this snapshot format needs to be documented and governed
|
||||
key: String(+Date.now()),
|
||||
meta: {
|
||||
language: translator.language(),
|
||||
|
||||
@@ -50,6 +50,9 @@ function snapshooter({ snapshotUrl, chrome = {} } = {}) {
|
||||
getStoredSnapshot(id) {
|
||||
return snapshots[id];
|
||||
},
|
||||
getStoredSnapshots() {
|
||||
return Object.keys(snapshots).map(key => snapshots[key]);
|
||||
},
|
||||
storeSnapshot(snapshot) {
|
||||
if (!snapshot) {
|
||||
throw new Error('Empty snapshot');
|
||||
|
||||
@@ -50,5 +50,9 @@ module.exports = function router({ base, snapshotUrl, snapshooter }) {
|
||||
}
|
||||
});
|
||||
|
||||
r.get('/snapshots', (req, res) => {
|
||||
res.json(snapshooter.getStoredSnapshots());
|
||||
});
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const express = require('express');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
|
||||
const snapshooter = require('@nebula.js/snapshooter');
|
||||
const snapshooterFn = require('@nebula.js/snapshooter');
|
||||
const snapshotRouter = require('./snapshot-router');
|
||||
|
||||
module.exports = async ({
|
||||
@@ -27,10 +27,16 @@ module.exports = async ({
|
||||
|
||||
const snapshotRoute = '/njs';
|
||||
|
||||
const snapshooter = snapshooterFn({ snapshotUrl: `http://${host}:${port}/eRender.html` });
|
||||
|
||||
(serveConfig.snapshots || []).forEach(s => {
|
||||
snapshooter.storeSnapshot(s);
|
||||
});
|
||||
|
||||
const snapRouter = snapshotRouter({
|
||||
base: `http://${host}:${port}${snapshotRoute}`,
|
||||
snapshotUrl: `http://${host}:${port}/eRender.html`,
|
||||
snapshooter: snapshooter({ snapshotUrl: `http://${host}:${port}/eRender.html` }),
|
||||
snapshooter,
|
||||
});
|
||||
|
||||
const themes = serveConfig.themes || [];
|
||||
|
||||
Reference in New Issue
Block a user