@plurid/plurid-react-server 0.0.0-1 → 0.0.0-12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  export declare const DEFAULT_SERVER_PORT: number;
2
2
  export declare const DEFAULT_SERVER_OPTIONS_SERVER_NAME = "Plurid Server";
3
+ export declare const DEFAULT_SERVER_OPTIONS_HOSTNAME = "origin";
3
4
  export declare const DEFAULT_SERVER_OPTIONS_QUIET = false;
4
5
  export declare const DEFAULT_SERVER_OPTIONS_COMPRESSION = true;
5
6
  export declare const DEFAULT_SERVER_OPTIONS_OPEN = false;
@@ -9,6 +10,7 @@ export declare const DEFAULT_SERVER_OPTIONS_STILLS_DIRECTORY = "stills";
9
10
  export declare const DEFAULT_SERVER_OPTIONS_GATEWAY = "/gateway";
10
11
  export declare const DEFAULT_SERVER_OPTIONS: {
11
12
  SERVER_NAME: string;
13
+ HOSTNAME: string;
12
14
  QUIET: boolean;
13
15
  COMPRESSION: boolean;
14
16
  OPEN: boolean;
@@ -1,2 +1,2 @@
1
- export * from "./general/index";
2
- export * from "./stiller/index";
1
+ export * from './general';
2
+ export * from './stiller';
@@ -1,2 +1,2 @@
1
- import { PluridStillerOptions } from "../../interfaces/index";
1
+ import { PluridStillerOptions } from "../../interfaces";
2
2
  export declare const defaultStillerOptions: PluridStillerOptions;
@@ -1,7 +1,6 @@
1
1
  import express from 'express';
2
2
  import { Helmet } from 'react-helmet-async';
3
- import { PluridRoute, PluridRoutePlane, PluridPreserve } from '@plurid/plurid-data';
4
- import { routing } from '@plurid/plurid-engine';
3
+ import { PluridRoute, PluridRoutePlane, PluridPreserve, IsoMatcherRouteResult } from '@plurid/plurid-data';
5
4
  import { PluridReactComponent } from '@plurid/plurid-react';
6
5
  export declare type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void;
7
6
  export declare type ServerRequest = express.Request & {
@@ -12,6 +11,11 @@ export declare type DebugLevels = 'none' | 'error' | 'warn' | 'info';
12
11
  export interface PluridServerOptions {
13
12
  /** To be used for logging. Default `Plurid Server` */
14
13
  serverName: string;
14
+ /**
15
+ * The hostname of the server exposed to the internet, e.g. `example.com`,
16
+ * to be used in plurid plane links.
17
+ */
18
+ hostname: string;
15
19
  /**
16
20
  * To log or not to log to the console.
17
21
  */
@@ -70,7 +74,7 @@ export interface PluridServerService<P = any> {
70
74
  export interface PluridServerConfiguration {
71
75
  routes: PluridRoute<PluridReactComponent>[];
72
76
  planes?: PluridRoutePlane<PluridReactComponent>[];
73
- preserves: PluridPreserve<routing.IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>[];
77
+ preserves: PluridPreserveReact[];
74
78
  helmet: Helmet;
75
79
  styles?: string[];
76
80
  middleware?: PluridServerMiddleware[];
@@ -141,3 +145,7 @@ export interface PluridStillerOptions {
141
145
  */
142
146
  ignore: string[];
143
147
  }
148
+ export declare type PluridPreserveReact = PluridPreserve<IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>;
149
+ export interface PluridLiveServerOptions {
150
+ server: string;
151
+ }
@@ -1,2 +1,2 @@
1
- export * from "./external/index";
2
- export * from "./internal/index";
1
+ export * from './external';
2
+ export * from './internal';
@@ -2,7 +2,7 @@ import { Helmet } from 'react-helmet-async';
2
2
  import { ServerStyleSheet } from 'styled-components';
3
3
  import { Indexed, PluridRoute, PluridRoutePlane, PluridPreserveResponse } from '@plurid/plurid-data';
4
4
  import { PluridReactComponent } from '@plurid/plurid-react';
5
- import { PluridServerService, PluridStillerOptions } from "../external/index";
5
+ import { PluridServerService, PluridStillerOptions } from '../external';
6
6
  export interface PluridRendererConfiguration {
7
7
  htmlLanguage: string | undefined;
8
8
  htmlAttributes: string;
@@ -60,6 +60,7 @@ export interface PluridContentGeneratorData {
60
60
  preserveResult: PluridPreserveResponse | undefined;
61
61
  matchedPlane: any;
62
62
  pathname: string;
63
+ hostname: string;
63
64
  }
64
65
  export interface RendererTemplateData {
65
66
  htmlLanguage: string;
@@ -1,5 +1,6 @@
1
- import PluridServer from "./objects/Server/index";
2
- import PluridStillsGenerator from "./objects/StillsGenerator/index";
3
- export * from "./data/interfaces/external/index";
4
- export { PluridStillsGenerator, };
1
+ import PluridServer from './objects/Server';
2
+ import PluridLiveServer from './objects/LiveServer';
3
+ import PluridStillsGenerator from './objects/StillsGenerator';
4
+ export * from './data/interfaces/external';
5
+ export { PluridLiveServer, PluridStillsGenerator, };
5
6
  export default PluridServer;
@@ -18,18 +18,20 @@ import { routing } from "@plurid/plurid-engine";
18
18
 
19
19
  import { PluridProvider, PluridRouterStatic, serverComputeMetastate } from "@plurid/plurid-react";
20
20
 
21
+ import { minify } from "html-minifier";
22
+
21
23
  import React from "react";
22
24
 
23
25
  import { renderToString } from "react-dom/server";
24
26
 
25
27
  import { HelmetProvider } from "react-helmet-async";
26
28
 
29
+ import http from "http";
30
+
27
31
  import { fork } from "child_process";
28
32
 
29
33
  import detectPort from "detect-port";
30
34
 
31
- import puppeteer from "puppeteer";
32
-
33
35
  function __awaiter(thisArg, _arguments, P, generator) {
34
36
  function adopt(value) {
35
37
  return value instanceof P ? value : new P((function(resolve) {
@@ -100,6 +102,8 @@ const DEFAULT_SERVER_PORT = process.env.PORT ? parseInt(process.env.PORT) : 8080
100
102
 
101
103
  const DEFAULT_SERVER_OPTIONS_SERVER_NAME = "Plurid Server";
102
104
 
105
+ const DEFAULT_SERVER_OPTIONS_HOSTNAME = "origin";
106
+
103
107
  const DEFAULT_SERVER_OPTIONS_QUIET = false;
104
108
 
105
109
  const DEFAULT_SERVER_OPTIONS_COMPRESSION = true;
@@ -116,6 +120,7 @@ const DEFAULT_SERVER_OPTIONS_GATEWAY = "/gateway";
116
120
 
117
121
  const DEFAULT_SERVER_OPTIONS = {
118
122
  SERVER_NAME: DEFAULT_SERVER_OPTIONS_SERVER_NAME,
123
+ HOSTNAME: DEFAULT_SERVER_OPTIONS_HOSTNAME,
119
124
  QUIET: DEFAULT_SERVER_OPTIONS_QUIET,
120
125
  COMPRESSION: DEFAULT_SERVER_OPTIONS_COMPRESSION,
121
126
  OPEN: DEFAULT_SERVER_OPTIONS_OPEN,
@@ -154,7 +159,9 @@ const defaultStillerOptions = {
154
159
  ignore: []
155
160
  };
156
161
 
157
- const cleanTemplate = template => template.replace(/(?:\r\n|\r|\n)/g, " ").replace(/ +/g, " ").trim();
162
+ const cleanTemplate = template => minify(template, {
163
+ collapseWhitespace: true
164
+ });
158
165
 
159
166
  const resolveBackgroundStyle = store => {
160
167
  var _a;
@@ -279,7 +286,7 @@ class PluridContentGenerator {
279
286
  console.log("Plurid Server Error :: Providers not loaded");
280
287
  return "";
281
288
  }
282
- const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname} = this.data;
289
+ const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
283
290
  const RoutedApplication = () => React.createElement(PluridProvider, {
284
291
  metastate: pluridMetastate
285
292
  }, React.createElement(PluridRouterStatic, {
@@ -291,7 +298,8 @@ class PluridContentGenerator {
291
298
  shell: shell,
292
299
  gateway: gateway,
293
300
  gatewayEndpoint: gatewayEndpoint,
294
- gatewayQuery: gatewayQuery
301
+ gatewayQuery: gatewayQuery,
302
+ hostname: hostname
295
303
  }));
296
304
  let Wrap = wrapping(HelmetProvider, RoutedApplication, {
297
305
  context: helmet
@@ -364,7 +372,7 @@ class PluridServer {
364
372
  this.isoMatcher = new PluridIsoMatcher({
365
373
  routes: this.routes,
366
374
  routePlanes: this.planes
367
- });
375
+ }, this.options.hostname);
368
376
  this.configureServer();
369
377
  this.handleEndpoints();
370
378
  process.addListener("SIGINT", (() => {
@@ -440,8 +448,7 @@ class PluridServer {
440
448
  if (this.debugAllows("info")) {
441
449
  console.info(`[${time.stamp()} :: ${requestID}] (000 Start) Handling GET ${request.path}`);
442
450
  }
443
- const path = request.originalUrl;
444
- const ignorable = this.ignoreGetRequest(path);
451
+ const ignorable = this.ignoreGetRequest(request.path);
445
452
  if (ignorable) {
446
453
  if (this.debugAllows("info")) {
447
454
  const requestTime = this.computeRequestTime(request);
@@ -458,7 +465,7 @@ class PluridServer {
458
465
  }
459
466
  return;
460
467
  }
461
- const {externalRedirect: externalRedirect, matchingPath: matchingPath} = this.resolveMatchingPath(preserveResult, path);
468
+ const {externalRedirect: externalRedirect, matchingPath: matchingPath} = this.resolveMatchingPath(preserveResult, request.originalUrl);
462
469
  if (externalRedirect) {
463
470
  if (this.debugAllows("info")) {
464
471
  const requestTime = this.computeRequestTime(request);
@@ -725,8 +732,9 @@ class PluridServer {
725
732
  renderApplication(isoMatch, preserveResult, matchedPlane) {
726
733
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
727
734
  return __awaiter(this, void 0, void 0, (function*() {
735
+ const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
728
736
  const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
729
- const pluridMetastate = serverComputeMetastate(isoMatch, this.routes);
737
+ const pluridMetastate = yield serverComputeMetastate(isoMatch, this.routes, globals);
730
738
  const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
731
739
  const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
732
740
  const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
@@ -742,7 +750,6 @@ class PluridServer {
742
750
  const mergedHeadScripts = [ ...headScripts, ...((_j = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _j === void 0 ? void 0 : _j.headScripts) || [] ];
743
751
  const bodyScripts = ((_k = this.template) === null || _k === void 0 ? void 0 : _k.bodyScripts) || [];
744
752
  const mergedBodyScripts = [ ...bodyScripts, ...((_l = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _l === void 0 ? void 0 : _l.bodyScripts) || [] ];
745
- const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
746
753
  const renderer = new PluridRenderer({
747
754
  htmlLanguage: mergedHtmlLanguage,
748
755
  head: head,
@@ -785,7 +792,8 @@ class PluridServer {
785
792
  gatewayEndpoint: gatewayEndpoint,
786
793
  gatewayQuery: gatewayQuery,
787
794
  preserveResult: preserveResult,
788
- pathname: isoMatch.kind === "Route" ? isoMatch.data.value : isoMatch.match.value,
795
+ pathname: isoMatch.match.value,
796
+ hostname: this.options.hostname,
789
797
  matchedPlane: isoMatch.kind === "RoutePlane" ? {
790
798
  value: isoMatch.match.value
791
799
  } : undefined
@@ -825,6 +833,7 @@ class PluridServer {
825
833
  var _a, _b;
826
834
  const options = {
827
835
  serverName: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.serverName) || DEFAULT_SERVER_OPTIONS.SERVER_NAME,
836
+ hostname: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.hostname) || DEFAULT_SERVER_OPTIONS.HOSTNAME,
828
837
  quiet: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.quiet) || DEFAULT_SERVER_OPTIONS.QUIET,
829
838
  debug: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.debug) ? partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.debug : environment.production ? "error" : "info",
830
839
  compression: (_a = partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.compression) !== null && _a !== void 0 ? _a : DEFAULT_SERVER_OPTIONS.COMPRESSION,
@@ -916,6 +925,37 @@ class PluridServer {
916
925
  }
917
926
  }
918
927
 
928
+ class LiveServer {
929
+ constructor(options) {
930
+ this.sockets = [];
931
+ this.resolveOptions = options => {
932
+ const defaultServerPath = "./source/server/index.ts";
933
+ const resolvedOptions = {
934
+ server: (options === null || options === void 0 ? void 0 : options.server) || defaultServerPath
935
+ };
936
+ return resolvedOptions;
937
+ };
938
+ this.options = this.resolveOptions(options);
939
+ this.expressServer = express();
940
+ this.setupExpressServer();
941
+ this.httpServer = http.createServer(this.expressServer);
942
+ this.setupHttpServer();
943
+ }
944
+ setupExpressServer() {}
945
+ setupHttpServer() {
946
+ this.httpServer.on("connection", (socket => {
947
+ this.sockets.push(socket);
948
+ socket.once("close", (() => {
949
+ this.sockets.splice(this.sockets.indexOf(socket), 1);
950
+ }));
951
+ }));
952
+ this.httpServer.on("error", (error => {
953
+ throw error;
954
+ }));
955
+ }
956
+ start() {}
957
+ }
958
+
919
959
  const replacePluridResolution = html => {
920
960
  const normalResolution = "width: 1366px; height: 768px;";
921
961
  const zeroResolution = "width: 0px; height: 0px;";
@@ -924,7 +964,7 @@ const replacePluridResolution = html => {
924
964
 
925
965
  const isCurrentUserRoot = () => process.getuid() == 0;
926
966
 
927
- const render = (host, route, configuration) => __awaiter(void 0, void 0, void 0, (function*() {
967
+ const render = (puppeteer, host, route, configuration) => __awaiter(void 0, void 0, void 0, (function*() {
928
968
  const start = Date.now();
929
969
  const browser = yield puppeteer.launch({
930
970
  defaultViewport: {
@@ -958,6 +998,11 @@ const render = (host, route, configuration) => __awaiter(void 0, void 0, void 0,
958
998
 
959
999
  class Stiller {
960
1000
  constructor(options) {
1001
+ try {
1002
+ this.puppeteer = require("puppeteer");
1003
+ } catch (error) {
1004
+ console.error("could not load puppeteer: check puppeteer is installed");
1005
+ }
961
1006
  const {host: host, routes: routes, configuration: configuration} = options;
962
1007
  this.host = host;
963
1008
  this.routes = routes;
@@ -966,7 +1011,7 @@ class Stiller {
966
1011
  still() {
967
1012
  return __asyncGenerator(this, arguments, (function* still_1() {
968
1013
  for (const route of this.routes) {
969
- yield yield __await(yield __await(render(this.host, route, this.configuration)));
1014
+ yield yield __await(yield __await(render(this.puppeteer, this.host, route, this.configuration)));
970
1015
  }
971
1016
  }));
972
1017
  }
@@ -1063,6 +1108,4 @@ class StillsGenerator {
1063
1108
  }
1064
1109
  }
1065
1110
 
1066
- export default PluridServer;
1067
-
1068
- export { StillsGenerator as PluridStillsGenerator };
1111
+ export { LiveServer as PluridLiveServer, StillsGenerator as PluridStillsGenerator, PluridServer as default };
@@ -24,18 +24,20 @@ var pluridEngine = require("@plurid/plurid-engine");
24
24
 
25
25
  var pluridReact = require("@plurid/plurid-react");
26
26
 
27
+ var htmlMinifier = require("html-minifier");
28
+
27
29
  var React = require("react");
28
30
 
29
31
  var server = require("react-dom/server");
30
32
 
31
33
  var reactHelmetAsync = require("react-helmet-async");
32
34
 
35
+ var http = require("http");
36
+
33
37
  var child_process = require("child_process");
34
38
 
35
39
  var detectPort = require("detect-port");
36
40
 
37
- var puppeteer = require("puppeteer");
38
-
39
41
  function _interopDefaultLegacy(e) {
40
42
  return e && typeof e === "object" && "default" in e ? e : {
41
43
  default: e
@@ -74,9 +76,9 @@ var open__default = _interopDefaultLegacy(open);
74
76
 
75
77
  var React__default = _interopDefaultLegacy(React);
76
78
 
77
- var detectPort__default = _interopDefaultLegacy(detectPort);
79
+ var http__default = _interopDefaultLegacy(http);
78
80
 
79
- var puppeteer__default = _interopDefaultLegacy(puppeteer);
81
+ var detectPort__default = _interopDefaultLegacy(detectPort);
80
82
 
81
83
  function __awaiter(thisArg, _arguments, P, generator) {
82
84
  function adopt(value) {
@@ -148,6 +150,8 @@ const DEFAULT_SERVER_PORT = process.env.PORT ? parseInt(process.env.PORT) : 8080
148
150
 
149
151
  const DEFAULT_SERVER_OPTIONS_SERVER_NAME = "Plurid Server";
150
152
 
153
+ const DEFAULT_SERVER_OPTIONS_HOSTNAME = "origin";
154
+
151
155
  const DEFAULT_SERVER_OPTIONS_QUIET = false;
152
156
 
153
157
  const DEFAULT_SERVER_OPTIONS_COMPRESSION = true;
@@ -164,6 +168,7 @@ const DEFAULT_SERVER_OPTIONS_GATEWAY = "/gateway";
164
168
 
165
169
  const DEFAULT_SERVER_OPTIONS = {
166
170
  SERVER_NAME: DEFAULT_SERVER_OPTIONS_SERVER_NAME,
171
+ HOSTNAME: DEFAULT_SERVER_OPTIONS_HOSTNAME,
167
172
  QUIET: DEFAULT_SERVER_OPTIONS_QUIET,
168
173
  COMPRESSION: DEFAULT_SERVER_OPTIONS_COMPRESSION,
169
174
  OPEN: DEFAULT_SERVER_OPTIONS_OPEN,
@@ -202,7 +207,9 @@ const defaultStillerOptions = {
202
207
  ignore: []
203
208
  };
204
209
 
205
- const cleanTemplate = template => template.replace(/(?:\r\n|\r|\n)/g, " ").replace(/ +/g, " ").trim();
210
+ const cleanTemplate = template => htmlMinifier.minify(template, {
211
+ collapseWhitespace: true
212
+ });
206
213
 
207
214
  const resolveBackgroundStyle = store => {
208
215
  var _a;
@@ -327,7 +334,7 @@ class PluridContentGenerator {
327
334
  console.log("Plurid Server Error :: Providers not loaded");
328
335
  return "";
329
336
  }
330
- const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname} = this.data;
337
+ const {pluridMetastate: pluridMetastate, routes: routes, planes: planes, exterior: exterior, shell: shell, gateway: gateway, gatewayEndpoint: gatewayEndpoint, gatewayQuery: gatewayQuery, helmet: helmet, services: services, stylesheet: stylesheet, preserveResult: preserveResult, matchedPlane: matchedPlane, pathname: pathname, hostname: hostname} = this.data;
331
338
  const RoutedApplication = () => React__default["default"].createElement(pluridReact.PluridProvider, {
332
339
  metastate: pluridMetastate
333
340
  }, React__default["default"].createElement(pluridReact.PluridRouterStatic, {
@@ -339,7 +346,8 @@ class PluridContentGenerator {
339
346
  shell: shell,
340
347
  gateway: gateway,
341
348
  gatewayEndpoint: gatewayEndpoint,
342
- gatewayQuery: gatewayQuery
349
+ gatewayQuery: gatewayQuery,
350
+ hostname: hostname
343
351
  }));
344
352
  let Wrap = wrapping(reactHelmetAsync.HelmetProvider, RoutedApplication, {
345
353
  context: helmet
@@ -359,9 +367,11 @@ class PluridContentGenerator {
359
367
  const providers = {};
360
368
  for (const service of this.data.services) {
361
369
  try {
362
- const importedService = yield Promise.resolve().then((function() {
363
- return _interopNamespace(require(service.package));
364
- }));
370
+ const importedService = yield function(t) {
371
+ return Promise.resolve().then((function() {
372
+ return _interopNamespace(require(t));
373
+ }));
374
+ }(service.package);
365
375
  const ImportedServiceProvider = service.provider === "default" ? importedService : importedService[service.provider];
366
376
  providers[service.name] = ImportedServiceProvider;
367
377
  } catch (error) {
@@ -414,7 +424,7 @@ class PluridServer {
414
424
  this.isoMatcher = new PluridIsoMatcher({
415
425
  routes: this.routes,
416
426
  routePlanes: this.planes
417
- });
427
+ }, this.options.hostname);
418
428
  this.configureServer();
419
429
  this.handleEndpoints();
420
430
  process.addListener("SIGINT", (() => {
@@ -490,8 +500,7 @@ class PluridServer {
490
500
  if (this.debugAllows("info")) {
491
501
  console.info(`[${pluridFunctions.time.stamp()} :: ${requestID}] (000 Start) Handling GET ${request.path}`);
492
502
  }
493
- const path = request.originalUrl;
494
- const ignorable = this.ignoreGetRequest(path);
503
+ const ignorable = this.ignoreGetRequest(request.path);
495
504
  if (ignorable) {
496
505
  if (this.debugAllows("info")) {
497
506
  const requestTime = this.computeRequestTime(request);
@@ -508,7 +517,7 @@ class PluridServer {
508
517
  }
509
518
  return;
510
519
  }
511
- const {externalRedirect: externalRedirect, matchingPath: matchingPath} = this.resolveMatchingPath(preserveResult, path);
520
+ const {externalRedirect: externalRedirect, matchingPath: matchingPath} = this.resolveMatchingPath(preserveResult, request.originalUrl);
512
521
  if (externalRedirect) {
513
522
  if (this.debugAllows("info")) {
514
523
  const requestTime = this.computeRequestTime(request);
@@ -775,8 +784,9 @@ class PluridServer {
775
784
  renderApplication(isoMatch, preserveResult, matchedPlane) {
776
785
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
777
786
  return __awaiter(this, void 0, void 0, (function*() {
787
+ const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
778
788
  const mergedHtmlLanguage = ((_a = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _a === void 0 ? void 0 : _a.htmlLanguage) || ((_b = this.template) === null || _b === void 0 ? void 0 : _b.htmlLanguage);
779
- const pluridMetastate = pluridReact.serverComputeMetastate(isoMatch, this.routes);
789
+ const pluridMetastate = yield pluridReact.serverComputeMetastate(isoMatch, this.routes, globals);
780
790
  const {content: content, styles: styles} = yield this.getContentAndStyles(isoMatch, pluridMetastate, preserveResult, matchedPlane);
781
791
  const stringedStyles = this.styles.reduce(((accumulator, style) => accumulator + style), "");
782
792
  const preserveStyles = ((_d = (_c = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _c === void 0 ? void 0 : _c.styles) === null || _d === void 0 ? void 0 : _d.join(" ")) || "";
@@ -792,7 +802,6 @@ class PluridServer {
792
802
  const mergedHeadScripts = [ ...headScripts, ...((_j = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _j === void 0 ? void 0 : _j.headScripts) || [] ];
793
803
  const bodyScripts = ((_k = this.template) === null || _k === void 0 ? void 0 : _k.bodyScripts) || [];
794
804
  const mergedBodyScripts = [ ...bodyScripts, ...((_l = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.template) === null || _l === void 0 ? void 0 : _l.bodyScripts) || [] ];
795
- const globals = preserveResult === null || preserveResult === void 0 ? void 0 : preserveResult.globals;
796
805
  const renderer = new PluridRenderer({
797
806
  htmlLanguage: mergedHtmlLanguage,
798
807
  head: head,
@@ -835,7 +844,8 @@ class PluridServer {
835
844
  gatewayEndpoint: gatewayEndpoint,
836
845
  gatewayQuery: gatewayQuery,
837
846
  preserveResult: preserveResult,
838
- pathname: isoMatch.kind === "Route" ? isoMatch.data.value : isoMatch.match.value,
847
+ pathname: isoMatch.match.value,
848
+ hostname: this.options.hostname,
839
849
  matchedPlane: isoMatch.kind === "RoutePlane" ? {
840
850
  value: isoMatch.match.value
841
851
  } : undefined
@@ -875,6 +885,7 @@ class PluridServer {
875
885
  var _a, _b;
876
886
  const options = {
877
887
  serverName: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.serverName) || DEFAULT_SERVER_OPTIONS.SERVER_NAME,
888
+ hostname: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.hostname) || DEFAULT_SERVER_OPTIONS.HOSTNAME,
878
889
  quiet: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.quiet) || DEFAULT_SERVER_OPTIONS.QUIET,
879
890
  debug: (partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.debug) ? partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.debug : environment.production ? "error" : "info",
880
891
  compression: (_a = partialOptions === null || partialOptions === void 0 ? void 0 : partialOptions.compression) !== null && _a !== void 0 ? _a : DEFAULT_SERVER_OPTIONS.COMPRESSION,
@@ -966,6 +977,37 @@ class PluridServer {
966
977
  }
967
978
  }
968
979
 
980
+ class LiveServer {
981
+ constructor(options) {
982
+ this.sockets = [];
983
+ this.resolveOptions = options => {
984
+ const defaultServerPath = "./source/server/index.ts";
985
+ const resolvedOptions = {
986
+ server: (options === null || options === void 0 ? void 0 : options.server) || defaultServerPath
987
+ };
988
+ return resolvedOptions;
989
+ };
990
+ this.options = this.resolveOptions(options);
991
+ this.expressServer = express__default["default"]();
992
+ this.setupExpressServer();
993
+ this.httpServer = http__default["default"].createServer(this.expressServer);
994
+ this.setupHttpServer();
995
+ }
996
+ setupExpressServer() {}
997
+ setupHttpServer() {
998
+ this.httpServer.on("connection", (socket => {
999
+ this.sockets.push(socket);
1000
+ socket.once("close", (() => {
1001
+ this.sockets.splice(this.sockets.indexOf(socket), 1);
1002
+ }));
1003
+ }));
1004
+ this.httpServer.on("error", (error => {
1005
+ throw error;
1006
+ }));
1007
+ }
1008
+ start() {}
1009
+ }
1010
+
969
1011
  const replacePluridResolution = html => {
970
1012
  const normalResolution = "width: 1366px; height: 768px;";
971
1013
  const zeroResolution = "width: 0px; height: 0px;";
@@ -974,9 +1016,9 @@ const replacePluridResolution = html => {
974
1016
 
975
1017
  const isCurrentUserRoot = () => process.getuid() == 0;
976
1018
 
977
- const render = (host, route, configuration) => __awaiter(void 0, void 0, void 0, (function*() {
1019
+ const render = (puppeteer, host, route, configuration) => __awaiter(void 0, void 0, void 0, (function*() {
978
1020
  const start = Date.now();
979
- const browser = yield puppeteer__default["default"].launch({
1021
+ const browser = yield puppeteer.launch({
980
1022
  defaultViewport: {
981
1023
  width: 1366,
982
1024
  height: 768
@@ -1008,6 +1050,11 @@ const render = (host, route, configuration) => __awaiter(void 0, void 0, void 0,
1008
1050
 
1009
1051
  class Stiller {
1010
1052
  constructor(options) {
1053
+ try {
1054
+ this.puppeteer = require("puppeteer");
1055
+ } catch (error) {
1056
+ console.error("could not load puppeteer: check puppeteer is installed");
1057
+ }
1011
1058
  const {host: host, routes: routes, configuration: configuration} = options;
1012
1059
  this.host = host;
1013
1060
  this.routes = routes;
@@ -1016,7 +1063,7 @@ class Stiller {
1016
1063
  still() {
1017
1064
  return __asyncGenerator(this, arguments, (function* still_1() {
1018
1065
  for (const route of this.routes) {
1019
- yield yield __await(yield __await(render(this.host, route, this.configuration)));
1066
+ yield yield __await(yield __await(render(this.puppeteer, this.host, route, this.configuration)));
1020
1067
  }
1021
1068
  }));
1022
1069
  }
@@ -1113,6 +1160,8 @@ class StillsGenerator {
1113
1160
  }
1114
1161
  }
1115
1162
 
1163
+ exports.PluridLiveServer = LiveServer;
1164
+
1116
1165
  exports.PluridStillsGenerator = StillsGenerator;
1117
1166
 
1118
- exports.default = PluridServer;
1167
+ exports["default"] = PluridServer;
@@ -1,4 +1,4 @@
1
- import { PluridContentGeneratorData } from "../../data/interfaces/index";
1
+ import { PluridContentGeneratorData } from "../../data/interfaces";
2
2
  declare class PluridContentGenerator {
3
3
  private data;
4
4
  private providers;
@@ -0,0 +1,13 @@
1
+ import { PluridLiveServerOptions } from "../../data/interfaces";
2
+ declare class LiveServer {
3
+ private options;
4
+ private expressServer;
5
+ private httpServer;
6
+ private sockets;
7
+ constructor(options?: Partial<PluridLiveServerOptions>);
8
+ private resolveOptions;
9
+ private setupExpressServer;
10
+ private setupHttpServer;
11
+ start(): void;
12
+ }
13
+ export default LiveServer;
@@ -1,4 +1,4 @@
1
- import { PluridRendererConfiguration } from "../../data/interfaces/index";
1
+ import { PluridRendererConfiguration } from "../../data/interfaces";
2
2
  declare class PluridRenderer {
3
3
  private htmlLanguage;
4
4
  private head;
@@ -1,3 +1,3 @@
1
- import { RendererTemplateData } from "../../../data/interfaces/index";
1
+ import { RendererTemplateData } from "../../../data/interfaces";
2
2
  declare const template: (data: RendererTemplateData) => string;
3
3
  export default template;
@@ -3,7 +3,7 @@ import { Server } from 'http';
3
3
  import express from 'express';
4
4
  import { PluridRoute } from '@plurid/plurid-data';
5
5
  import { PluridReactComponent } from '@plurid/plurid-react';
6
- import { PluridServerOptions, PluridServerConfiguration } from "../../data/interfaces/index";
6
+ import { PluridServerOptions, PluridServerConfiguration } from "../../data/interfaces";
7
7
  declare class PluridServer {
8
8
  private routes;
9
9
  private planes;
@@ -25,7 +25,7 @@ declare class PluridServer {
25
25
  private isoMatcher;
26
26
  constructor(configuration: PluridServerConfiguration);
27
27
  static analysis(pluridServer: PluridServer): {
28
- routes: PluridRoute<PluridReactComponent<any>>[];
28
+ routes: PluridRoute<PluridReactComponent<any, import("@plurid/plurid-data").PluridPlaneComponentProperty | import("@plurid/plurid-data").PluridRouteComponentProperty>, any>[];
29
29
  options: PluridServerOptions;
30
30
  };
31
31
  start(port?: string | number): Server;
@@ -1,4 +1,4 @@
1
- import { StillerOptions } from "../../data/interfaces/index";
1
+ import { StillerOptions } from "../../data/interfaces";
2
2
  /**
3
3
  * The Server will parse the given application routes,
4
4
  * and will decide which ones to send to the Stiller.
@@ -10,6 +10,7 @@ import { StillerOptions } from "../../data/interfaces/index";
10
10
  * to serve the adequate plurid space structure when asked for the given route.
11
11
  */
12
12
  declare class Stiller {
13
+ private puppeteer;
13
14
  private host;
14
15
  private routes;
15
16
  private configuration;
@@ -1,4 +1,4 @@
1
- import { StillsGeneratorOptions } from "../../data/interfaces/index";
1
+ import { StillsGeneratorOptions } from "../../data/interfaces";
2
2
  declare class StillsGenerator {
3
3
  private options;
4
4
  constructor(options?: Partial<StillsGeneratorOptions>);
@@ -1,4 +1,4 @@
1
- import { PluridServerOptions } from "../../data/interfaces/index";
1
+ import { PluridServerOptions } from "../../data/interfaces";
2
2
  declare class StillsManager {
3
3
  private options;
4
4
  private stills;
@@ -1,6 +1,6 @@
1
- import { routing } from '@plurid/plurid-engine';
1
+ import { IsoMatcherPlaneResult } from '@plurid/plurid-data';
2
2
  import { PluridReactComponent } from '@plurid/plurid-react';
3
- export declare const resolveElementFromPlaneMatch: (planeMatch: routing.IsoMatcherPlaneResult<PluridReactComponent<any>>, elementqlEndpoint: string | undefined) => {
3
+ export declare const resolveElementFromPlaneMatch: (planeMatch: IsoMatcherPlaneResult<PluridReactComponent<any>>, elementqlEndpoint: string | undefined) => {
4
4
  name: string;
5
5
  url: string | undefined;
6
6
  } | undefined;
@@ -2,12 +2,10 @@ import React from 'react';
2
2
  declare const wrapping: (WrappedComponent: any, WrappeeComponent: any, properties: any) => {
3
3
  new (props: any): {
4
4
  render(): JSX.Element;
5
- context: any;
5
+ context: unknown;
6
6
  setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
7
7
  forceUpdate(callback?: (() => void) | undefined): void;
8
- readonly props: Readonly<{}> & Readonly<{
9
- children?: React.ReactNode;
10
- }>;
8
+ readonly props: Readonly<{}>;
11
9
  state: Readonly<{}>;
12
10
  refs: {
13
11
  [key: string]: React.ReactInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurid/plurid-react-server",
3
- "version": "0.0.0-1",
3
+ "version": "0.0.0-12",
4
4
  "description": "React implementation of Plurid to view and explore the web in three dimensions with server-side rendering",
5
5
  "keywords": [
6
6
  "plurid",
@@ -39,12 +39,12 @@
39
39
  "clean": "rm -rf ./distribution",
40
40
  "test": "jest ./source --config ./configurations/jest.config.js --rootDir ./",
41
41
  "lint": "eslint -c ./configurations/.eslintrc.js ./source --ext .ts,.tsx",
42
- "start": "yarn clean && rollup -c ./scripts/rollup.development.js -w --environment ENV_MODE:local",
43
- "build.development": "yarn clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:development",
44
- "build.production": "yarn clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:production",
45
- "build": "yarn clean && yarn lint && yarn test && yarn build.production",
42
+ "start": "pnpm clean && rollup -c ./scripts/rollup.development.js -w --environment ENV_MODE:local",
43
+ "build.development": "pnpm clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:development",
44
+ "build.production": "pnpm clean && rollup -c ./scripts/rollup.config.js --environment ENV_MODE:production",
45
+ "build": "pnpm clean && pnpm lint && pnpm test && pnpm build.production",
46
46
  "esbuild": "esbuild source/index.ts --bundle --platform=node --outfile=distribution/index.js --external:react",
47
- "prepublishOnly": "yarn build"
47
+ "prepublishOnly": "pnpm build"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@plurid/elementql": "*",
@@ -60,7 +60,6 @@
60
60
  "@plurid/plurid-ui-components-react": "*",
61
61
  "@plurid/plurid-ui-state-react": "*",
62
62
  "cross-fetch": ">=3.1",
63
- "puppeteer": ">=2.1",
64
63
  "react": ">=16.8",
65
64
  "react-dom": ">=16.8",
66
65
  "react-helmet-async": ">=1",
@@ -69,66 +68,68 @@
69
68
  "styled-components": ">=5"
70
69
  },
71
70
  "dependencies": {
72
- "body-parser": "^1.19.0",
71
+ "body-parser": "^1.20.0",
73
72
  "compression": "^1.7.4",
74
73
  "detect-port": "^1.3.0",
75
- "express": "^4.17.1",
76
- "open": "^8.0.8"
74
+ "express": "^4.18.1",
75
+ "html-minifier": "^4.0.0",
76
+ "open": "^8.4.0"
77
77
  },
78
78
  "devDependencies": {
79
- "@apollo/client": "^3.3.18",
80
- "@babel/core": "^7.14.2",
79
+ "@apollo/client": "^3.6.9",
80
+ "@babel/core": "^7.18.10",
81
81
  "@plurid/elementql": "^0.0.0-1",
82
82
  "@plurid/elementql-client-react": "^0.0.0-1",
83
- "@plurid/plurid-data": "0.0.0-3",
84
- "@plurid/plurid-engine": "0.0.0-2",
85
- "@plurid/plurid-functions": "0.0.0-3",
86
- "@plurid/plurid-functions-react": "0.0.0-1",
87
- "@plurid/plurid-icons-react": "0.0.0-0",
88
- "@plurid/plurid-pubsub": "0.0.0-4",
89
- "@plurid/plurid-react": "0.0.0-3",
90
- "@plurid/plurid-themes": "0.0.0-0",
91
- "@plurid/plurid-ui-components-react": "0.0.0-1",
92
- "@plurid/plurid-ui-state-react": "0.0.0-0",
93
- "@rollup/plugin-node-resolve": "^13.0.0",
94
- "@types/body-parser": "^1.19.0",
95
- "@types/compression": "^1.7.0",
96
- "@types/detect-port": "^1.3.0",
97
- "@types/express": "^4.17.11",
98
- "@types/hammerjs": "^2.0.39",
99
- "@types/jest": "^26.0.23",
100
- "@types/puppeteer": "^5.4.3",
101
- "@types/react": "^17.0.5",
102
- "@types/react-dom": "^17.0.5",
103
- "@types/react-redux": "^7.1.16",
104
- "@types/react-stripe-elements": "^6.0.4",
105
- "@types/styled-components": "^5.1.9",
106
- "@typescript-eslint/eslint-plugin": "^4.23.0",
107
- "@typescript-eslint/parser": "^4.23.0",
83
+ "@plurid/plurid-data": "0.0.0-15",
84
+ "@plurid/plurid-engine": "0.0.0-14",
85
+ "@plurid/plurid-functions": "0.0.0-28",
86
+ "@plurid/plurid-functions-react": "0.0.0-5",
87
+ "@plurid/plurid-icons-react": "0.0.0-5",
88
+ "@plurid/plurid-pubsub": "0.0.0-7",
89
+ "@plurid/plurid-react": "0.0.0-24",
90
+ "@plurid/plurid-themes": "0.0.0-2",
91
+ "@plurid/plurid-ui-components-react": "0.0.0-15",
92
+ "@plurid/plurid-ui-state-react": "0.0.0-6",
93
+ "@redux-devtools/extension": "^3.2.3",
94
+ "@rollup/plugin-node-resolve": "^13.3.0",
95
+ "@types/body-parser": "^1.19.2",
96
+ "@types/compression": "^1.7.2",
97
+ "@types/detect-port": "^1.3.2",
98
+ "@types/express": "^4.17.13",
99
+ "@types/hammerjs": "^2.0.41",
100
+ "@types/html-minifier": "^4.0.2",
101
+ "@types/jest": "^28.1.6",
102
+ "@types/node": "^18.7.4",
103
+ "@types/react": "^18.0.17",
104
+ "@types/react-dom": "^18.0.6",
105
+ "@types/react-redux": "^7.1.24",
106
+ "@types/react-stripe-elements": "^6.0.6",
107
+ "@types/styled-components": "^5.1.26",
108
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
109
+ "@typescript-eslint/parser": "^5.33.0",
108
110
  "@zerollup/ts-transform-paths": "^1.7.18",
109
- "cross-fetch": "^3.1.4",
110
- "eslint": "^7.26.0",
111
- "graphql": "^15.5.0",
111
+ "cross-fetch": "^3.1.5",
112
+ "eslint": "^8.22.0",
113
+ "graphql": "^16.5.0",
112
114
  "hammerjs": "^2.0.8",
113
- "jest": "^26.6.3",
114
- "jest-config": "^26.6.3",
115
- "puppeteer": "^9.1.1",
116
- "react": "^17.0.2",
117
- "react-dom": "^17.0.2",
118
- "react-helmet-async": "^1.0.9",
119
- "react-redux": "^7.2.4",
120
- "redux": "^4.1.0",
121
- "redux-devtools-extension": "^2.13.9",
122
- "redux-thunk": "^2.3.0",
123
- "rollup": "^2.47.0",
115
+ "jest": "^28.1.3",
116
+ "jest-config": "^28.1.3",
117
+ "react": "^18.2.0",
118
+ "react-dom": "^18.2.0",
119
+ "react-helmet-async": "^1.3.0",
120
+ "react-redux": "^8.0.2",
121
+ "redux": "^4.2.0",
122
+ "redux-thunk": "^2.4.1",
123
+ "rollup": "^2.78.0",
124
124
  "rollup-plugin-peer-deps-external": "^2.2.4",
125
125
  "rollup-plugin-terser": "^7.0.2",
126
- "rollup-plugin-typescript2": "^0.30.0",
127
- "styled-components": "^5.3.0",
128
- "ts-jest": "^26.5.6",
129
- "ts-node": "^9.1.1",
130
- "ttypescript": "^1.5.12",
131
- "typescript": "^4.2.4",
132
- "typescript-transform-paths": "^2.2.3"
126
+ "rollup-plugin-typescript2": "^0.32.1",
127
+ "styled-components": "^5.3.5",
128
+ "ts-jest": "^28.0.8",
129
+ "ts-node": "^10.9.1",
130
+ "tslib": "^2.4.0",
131
+ "ttypescript": "^1.5.13",
132
+ "typescript": "^4.7.4",
133
+ "typescript-transform-paths": "^3.3.1"
133
134
  }
134
135
  }