@plurid/plurid-react-server 0.0.0-15 → 0.0.0-17
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.
- package/README.md +69 -5
- package/distribution/index.d.mts +296 -0
- package/distribution/index.d.ts +296 -6
- package/distribution/index.js +1644 -1058
- package/distribution/index.js.map +1 -0
- package/distribution/index.mjs +1714 -0
- package/distribution/index.mjs.map +1 -0
- package/package.json +129 -133
- package/distribution/__tests__/sanity.test.d.ts +0 -0
- package/distribution/data/constants/general/index.d.ts +0 -34
- package/distribution/data/constants/index.d.ts +0 -2
- package/distribution/data/constants/stiller/index.d.ts +0 -2
- package/distribution/data/interfaces/external/index.d.ts +0 -152
- package/distribution/data/interfaces/index.d.ts +0 -2
- package/distribution/data/interfaces/internal/index.d.ts +0 -84
- package/distribution/data/templates/index.d.ts +0 -2
- package/distribution/index.es.js +0 -1098
- package/distribution/objects/ContentGenerator/index.d.ts +0 -7
- package/distribution/objects/LiveServer/index.d.ts +0 -13
- package/distribution/objects/Renderer/index.d.ts +0 -22
- package/distribution/objects/Renderer/template/index.d.ts +0 -3
- package/distribution/objects/Server/index.d.ts +0 -58
- package/distribution/objects/Stiller/__tests__/index.test.d.ts +0 -1
- package/distribution/objects/Stiller/index.d.ts +0 -24
- package/distribution/objects/StillsGenerator/index.d.ts +0 -8
- package/distribution/objects/StillsManager/index.d.ts +0 -9
- package/distribution/utilities/pttp/index.d.ts +0 -6
- package/distribution/utilities/template/index.d.ts +0 -9
- package/distribution/utilities/wrapping/index.d.ts +0 -28
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<a target="_blank" href="https://www.npmjs.com/package/@plurid/plurid-react-server">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/@plurid/plurid-react-server.svg?logo=npm&colorB=1380C3&style=for-the-badge" alt="Version">
|
|
7
7
|
</a>
|
|
8
|
-
<a target="_blank" href="https://github.com/plurid/plurid
|
|
8
|
+
<a target="_blank" href="https://github.com/plurid/plurid/blob/master/LICENSE">
|
|
9
9
|
<img src="https://img.shields.io/badge/license-DEL-blue.svg?colorB=1380C3&style=for-the-badge" alt="License: DEL">
|
|
10
10
|
</a>
|
|
11
11
|
</p>
|
|
@@ -17,9 +17,73 @@
|
|
|
17
17
|
</h1>
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
Server
|
|
20
|
+
Server-side rendering for [plurid'](https://github.com/plurid/plurid) — render a plurid 3D space to HTML on
|
|
21
|
+
the server (faster first paint, crawlable markup), with an optional **static "stills"** pipeline for
|
|
22
|
+
pre-rendering routes ahead of time.
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
`@plurid/plurid-react-server` is normally scaffolded by
|
|
28
|
+
[`@plurid/generate-plurid-app`](https://github.com/plurid/plurid/tree/master/packages/plurid-utilities/generate-plurid-app)
|
|
29
|
+
(server templates). The two runnable references are
|
|
30
|
+
[`fixtures/plurid-react-typescript-server`](https://github.com/plurid/plurid/tree/master/fixtures) and its
|
|
31
|
+
JavaScript twin.
|
|
32
|
+
|
|
33
|
+
``` bash
|
|
34
|
+
npm install @plurid/plurid-react-server
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Server-side rendering
|
|
39
|
+
|
|
40
|
+
`PluridServer` is an Express server: it matches the request route, computes the plurid metastate via
|
|
41
|
+
`@plurid/plurid-react`'s `serverComputeMetastate`, renders the React tree to HTML (styled-components +
|
|
42
|
+
`react-helmet-async`), injects the metastate, and responds. Construct it with your routes / planes / helmet
|
|
43
|
+
/ services and `start(port)` — see the server fixtures for a complete setup.
|
|
44
|
+
|
|
45
|
+
``` ts
|
|
46
|
+
import PluridServer from '@plurid/plurid-react-server';
|
|
47
|
+
|
|
48
|
+
const server = new PluridServer({ routes, planes, preserves, helmet, /* … */ });
|
|
49
|
+
server.start(3000);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Static stills (optional, Puppeteer)
|
|
54
|
+
|
|
55
|
+
A **still** is a route pre-rendered to static HTML ahead of time. When a still exists for a request, the
|
|
56
|
+
server sends it directly and skips on-the-fly rendering. Stills are entirely opt-in.
|
|
57
|
+
|
|
58
|
+
> **Puppeteer is an optional peer dependency** — only stills *generation* needs it; SSR does not. Install it
|
|
59
|
+
> where you generate stills:
|
|
60
|
+
> ``` bash
|
|
61
|
+
> npm install puppeteer
|
|
62
|
+
> ```
|
|
63
|
+
|
|
64
|
+
**Generating** stills (`PluridStillsGenerator`) — run it after building your server bundle:
|
|
65
|
+
|
|
66
|
+
``` ts
|
|
67
|
+
import { PluridStillsGenerator } from '@plurid/plurid-react-server';
|
|
68
|
+
|
|
69
|
+
// reads routes from the BUILT server (default ./build/server.js), spins it up on a free port,
|
|
70
|
+
// drives Puppeteer over each static (non-parameterized) route, and writes:
|
|
71
|
+
// build/stills/<uuid>.json (one per route) + build/stills/metadata.json (the route → file index)
|
|
72
|
+
await new PluridStillsGenerator({ server: './build/server.js', build: './build/' }).initialize();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The order matters: **build the server first**, then run the generator (it `require()`s the built bundle and
|
|
76
|
+
fails with a clear message if it's missing). Parameterized routes (`/x/:id`) and `stiller.ignore` routes are
|
|
77
|
+
skipped. One headless browser is reused across all routes; a navigation failure aborts the run with the
|
|
78
|
+
underlying reason rather than writing partial output.
|
|
79
|
+
|
|
80
|
+
**Serving** stills — automatic: on startup `PluridServer` loads `build/stills/metadata.json` (the
|
|
81
|
+
`stillsDirectory` under `buildDirectory`) and serves a matching still before falling back to live SSR. Tune
|
|
82
|
+
generation via the server's `stiller` option (`waitUntil`, `timeout`, `ignore`).
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Documentation
|
|
86
|
+
|
|
87
|
+
Full engine docs: the repo [`README`](https://github.com/plurid/plurid),
|
|
88
|
+
[`GETTING_STARTED`](https://github.com/plurid/plurid/blob/master/GETTING_STARTED.md), and
|
|
89
|
+
[`CONTROL_SURFACE`](https://github.com/plurid/plurid/blob/master/docs/CONTROL_SURFACE.md).
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { Server } from 'http';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { PluridPreserve, IsoMatcherRouteResult, PluridRoute, PluridRoutePlane, PluridRouterProperties } from '@plurid/plurid-data';
|
|
5
|
+
import { PluridReactComponent } from '@plurid/plurid-react';
|
|
6
|
+
import { Helmet } from 'react-helmet-async';
|
|
7
|
+
|
|
8
|
+
type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void;
|
|
9
|
+
type ServerRequest = express.Request & {
|
|
10
|
+
requestID: string;
|
|
11
|
+
requestTime: number;
|
|
12
|
+
};
|
|
13
|
+
type DebugLevels = 'none' | 'error' | 'warn' | 'info';
|
|
14
|
+
interface PluridServerOptions {
|
|
15
|
+
/** To be used for logging. Default `Plurid Server` */
|
|
16
|
+
serverName: string;
|
|
17
|
+
/**
|
|
18
|
+
* The hostname of the server exposed to the internet, e.g. `example.com`,
|
|
19
|
+
* to be used in plurid plane links.
|
|
20
|
+
*/
|
|
21
|
+
hostname: string;
|
|
22
|
+
/**
|
|
23
|
+
* To log or not to log to the console.
|
|
24
|
+
*/
|
|
25
|
+
quiet: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Debug levels.
|
|
28
|
+
*
|
|
29
|
+
* Production default: `error`.
|
|
30
|
+
* Development default: `info` and above.
|
|
31
|
+
*/
|
|
32
|
+
debug: DebugLevels;
|
|
33
|
+
/**
|
|
34
|
+
* Use `gzip` compression for the response. Default `true`.
|
|
35
|
+
*/
|
|
36
|
+
compression: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Open in browser at start.
|
|
39
|
+
*/
|
|
40
|
+
open: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Name of the directory where the files (server and client) are bundled.
|
|
43
|
+
*/
|
|
44
|
+
buildDirectory: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name of the directory where the assets files are bundled.
|
|
47
|
+
*/
|
|
48
|
+
assetsDirectory: string;
|
|
49
|
+
/**
|
|
50
|
+
* Directory of static assets (favicon, og-image, manifest, robots) served at
|
|
51
|
+
* the URL root `/`. Empty string (the default) resolves to
|
|
52
|
+
* `<buildDirectory>/public`; the mount is skipped if the directory does not
|
|
53
|
+
* exist, so apps without a public directory are unaffected. The framework
|
|
54
|
+
* points this at `source/public` during `plurid dev`.
|
|
55
|
+
*/
|
|
56
|
+
publicDirectory: string;
|
|
57
|
+
/**
|
|
58
|
+
* Default: `/gateway`.
|
|
59
|
+
*/
|
|
60
|
+
gatewayEndpoint: string;
|
|
61
|
+
/**
|
|
62
|
+
* Provide a `max-age` in milliseconds for http caching of the static serves.
|
|
63
|
+
* This can also be a string accepted by the `ms` module.
|
|
64
|
+
*
|
|
65
|
+
* Default: 0.
|
|
66
|
+
*/
|
|
67
|
+
staticCache: number | string;
|
|
68
|
+
/**
|
|
69
|
+
* Routes to be ignored when serving the application (`GET`).
|
|
70
|
+
*/
|
|
71
|
+
ignore: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Name of the directory where the stills are gathered.
|
|
74
|
+
*/
|
|
75
|
+
stillsDirectory: string;
|
|
76
|
+
stiller: PluridStillerOptions;
|
|
77
|
+
/**
|
|
78
|
+
* Install `SIGINT`/`SIGTERM` handlers that stop the server and call `process.exit`.
|
|
79
|
+
* Defaults to `true` (convenient for the CLI). Set to `false` when EMBEDDING the server
|
|
80
|
+
* in a host process you do not want it to terminate; then manage lifecycle via `stop()`.
|
|
81
|
+
*/
|
|
82
|
+
attachSignalHandlers: boolean;
|
|
83
|
+
}
|
|
84
|
+
type PluridServerPartialOptions = Partial<PluridServerOptions>;
|
|
85
|
+
interface PluridServerService<P = any, PP = any> {
|
|
86
|
+
name: string;
|
|
87
|
+
Provider: P;
|
|
88
|
+
properties?: PP;
|
|
89
|
+
}
|
|
90
|
+
interface PluridServerConfiguration {
|
|
91
|
+
routes: PluridRoute<PluridReactComponent>[];
|
|
92
|
+
planes?: PluridRoutePlane<PluridReactComponent>[];
|
|
93
|
+
preserves: PluridPreserveReact[];
|
|
94
|
+
helmet: Helmet;
|
|
95
|
+
styles?: string[];
|
|
96
|
+
middleware?: PluridServerMiddleware[];
|
|
97
|
+
exterior?: PluridReactComponent;
|
|
98
|
+
shell?: PluridReactComponent;
|
|
99
|
+
routerProperties?: Partial<PluridRouterProperties<PluridReactComponent>>;
|
|
100
|
+
/**
|
|
101
|
+
* Replace the internal plurid plane with a custom implementation.
|
|
102
|
+
*/
|
|
103
|
+
customPlane?: PluridReactComponent;
|
|
104
|
+
/**
|
|
105
|
+
* Services to be handled by the server.
|
|
106
|
+
*
|
|
107
|
+
* Supported: `GraphQL`, `Redux`, `Stripe`.
|
|
108
|
+
*/
|
|
109
|
+
services?: PluridServerService[];
|
|
110
|
+
options?: PluridServerPartialOptions;
|
|
111
|
+
template?: PluridServerTemplateConfiguration;
|
|
112
|
+
usePTTP?: boolean;
|
|
113
|
+
pttpHandler?: PTTPHandler;
|
|
114
|
+
elementqlEndpoint?: string;
|
|
115
|
+
}
|
|
116
|
+
type PTTPHandler = (path: string) => Promise<boolean>;
|
|
117
|
+
interface PluridServerTemplateConfiguration {
|
|
118
|
+
htmlLanguage?: string;
|
|
119
|
+
htmlAttributes?: Record<string, string>;
|
|
120
|
+
defaultStyle?: string;
|
|
121
|
+
headScripts?: string[];
|
|
122
|
+
bodyScripts?: string[];
|
|
123
|
+
/**
|
|
124
|
+
* The JavaScript vendor filepath to inject in the HTML template.
|
|
125
|
+
* Default `'/vendor.js'`.
|
|
126
|
+
*
|
|
127
|
+
* A CDN link can be used for better caching.
|
|
128
|
+
*/
|
|
129
|
+
vendorScriptSource?: string;
|
|
130
|
+
/**
|
|
131
|
+
* The JavaScript filename to inject in the HTML template.
|
|
132
|
+
*/
|
|
133
|
+
mainScriptSource?: string;
|
|
134
|
+
bodyAttributes?: Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* The ID of the root element in the HTML template.
|
|
137
|
+
*/
|
|
138
|
+
root?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Global variable name to be attached to window on the server-side
|
|
141
|
+
* to preload plurid metastate.
|
|
142
|
+
*
|
|
143
|
+
* Default: `__PRELOADED_PLURID_METASTATE__`
|
|
144
|
+
*/
|
|
145
|
+
defaultPreloadedPluridMetastate?: string;
|
|
146
|
+
minify?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Favicon links injected into `<head>`. A bare string is the primary icon
|
|
149
|
+
* (`rel="icon"`); the object expands to icon / apple-touch-icon / sized /
|
|
150
|
+
* mask-icon links plus a `theme-color` meta. Paths resolve against the served
|
|
151
|
+
* public directory (see `PluridServerOptions.publicDirectory`).
|
|
152
|
+
*/
|
|
153
|
+
favicon?: string | {
|
|
154
|
+
icon?: string;
|
|
155
|
+
apple?: string;
|
|
156
|
+
sizes?: Record<string, string>;
|
|
157
|
+
maskIcon?: string;
|
|
158
|
+
themeColor?: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Web app manifest href, injected as `<link rel="manifest">`.
|
|
162
|
+
*/
|
|
163
|
+
manifest?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Static `<head>` metadata injected AHEAD of the react-helmet-async output,
|
|
166
|
+
* so per-route `<Helmet>` tags still override these defaults.
|
|
167
|
+
*/
|
|
168
|
+
head?: {
|
|
169
|
+
title?: string;
|
|
170
|
+
description?: string;
|
|
171
|
+
meta?: Array<{
|
|
172
|
+
name?: string;
|
|
173
|
+
property?: string;
|
|
174
|
+
content: string;
|
|
175
|
+
}>;
|
|
176
|
+
links?: Array<{
|
|
177
|
+
rel: string;
|
|
178
|
+
href: string;
|
|
179
|
+
}>;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Override the built-in 500 error page HTML (sent on a render failure).
|
|
183
|
+
*/
|
|
184
|
+
errorHtml?: string;
|
|
185
|
+
}
|
|
186
|
+
interface PluridStillerOptions {
|
|
187
|
+
/**
|
|
188
|
+
* Recommended: `'networkidle0'` | `'networkidle2'` | `'load'`.
|
|
189
|
+
*
|
|
190
|
+
* Default: `'networkidle0'`.
|
|
191
|
+
*/
|
|
192
|
+
waitUntil: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
|
|
193
|
+
/**
|
|
194
|
+
* Maximum navigation time in milliseconds, pass 0 to disable timeout.
|
|
195
|
+
*
|
|
196
|
+
* Default: 30000.
|
|
197
|
+
*/
|
|
198
|
+
timeout: number;
|
|
199
|
+
/**
|
|
200
|
+
* Routes to be ignored by the stilling process.
|
|
201
|
+
*/
|
|
202
|
+
ignore: string[];
|
|
203
|
+
}
|
|
204
|
+
type PluridPreserveReact = PluridPreserve<IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>;
|
|
205
|
+
interface PluridLiveServerOptions {
|
|
206
|
+
server: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface StillsGeneratorOptions {
|
|
210
|
+
server: string;
|
|
211
|
+
build: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare class PluridServer {
|
|
215
|
+
private routes;
|
|
216
|
+
private planes;
|
|
217
|
+
private preserves;
|
|
218
|
+
private helmet;
|
|
219
|
+
private styles;
|
|
220
|
+
private middleware;
|
|
221
|
+
private exterior;
|
|
222
|
+
private shell;
|
|
223
|
+
private routerProperties;
|
|
224
|
+
private services;
|
|
225
|
+
private options;
|
|
226
|
+
private template;
|
|
227
|
+
usePTTP: boolean;
|
|
228
|
+
private pttpHandler;
|
|
229
|
+
private elementqlEndpoint;
|
|
230
|
+
private serverApplication;
|
|
231
|
+
private server;
|
|
232
|
+
private port;
|
|
233
|
+
private stills;
|
|
234
|
+
private isoMatcher;
|
|
235
|
+
constructor(configuration: PluridServerConfiguration);
|
|
236
|
+
private handleProcessSignal;
|
|
237
|
+
private signalHandlersAttached;
|
|
238
|
+
attachSignalHandlers(): void;
|
|
239
|
+
detachSignalHandlers(): void;
|
|
240
|
+
static analysis(pluridServer: PluridServer): {
|
|
241
|
+
routes: PluridRoute<PluridReactComponent, any>[];
|
|
242
|
+
options: PluridServerOptions;
|
|
243
|
+
};
|
|
244
|
+
start(port?: string | number): Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
245
|
+
stop(): void;
|
|
246
|
+
handle(): {
|
|
247
|
+
post: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
248
|
+
patch: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
249
|
+
put: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
250
|
+
delete: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
251
|
+
};
|
|
252
|
+
instance(): express.Express;
|
|
253
|
+
private handleEndpoints;
|
|
254
|
+
private handleGetRequest;
|
|
255
|
+
private handlePTTPRequest;
|
|
256
|
+
private ignoreGetRequest;
|
|
257
|
+
private resolveMatchingPath;
|
|
258
|
+
private resolvePreserve;
|
|
259
|
+
private resolvePreserveAfterServe;
|
|
260
|
+
private handleGateway;
|
|
261
|
+
private renderApplication;
|
|
262
|
+
/**
|
|
263
|
+
* Build the static `<head>` markup from the template config (favicon set,
|
|
264
|
+
* manifest, default title / meta / links). Returns an empty string when none
|
|
265
|
+
* are configured, so the head is byte-identical to before for existing apps.
|
|
266
|
+
*/
|
|
267
|
+
private buildStaticHead;
|
|
268
|
+
private getContentAndStyles;
|
|
269
|
+
private computeRequestTime;
|
|
270
|
+
private handleOptions;
|
|
271
|
+
private configureServer;
|
|
272
|
+
private loadMiddleware;
|
|
273
|
+
private open;
|
|
274
|
+
private debugAllows;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
declare class LiveServer {
|
|
278
|
+
private options;
|
|
279
|
+
private expressServer;
|
|
280
|
+
private httpServer;
|
|
281
|
+
private sockets;
|
|
282
|
+
constructor(options?: Partial<PluridLiveServerOptions>);
|
|
283
|
+
private resolveOptions;
|
|
284
|
+
private setupExpressServer;
|
|
285
|
+
private setupHttpServer;
|
|
286
|
+
start(): never;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare class StillsGenerator {
|
|
290
|
+
private options;
|
|
291
|
+
constructor(options?: Partial<StillsGeneratorOptions>);
|
|
292
|
+
resolveOptions(options?: Partial<StillsGeneratorOptions>): StillsGeneratorOptions;
|
|
293
|
+
initialize(): Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { type DebugLevels, type PTTPHandler, LiveServer as PluridLiveServer, type PluridLiveServerOptions, type PluridPreserveReact, type PluridServerConfiguration, type PluridServerMiddleware, type PluridServerOptions, type PluridServerPartialOptions, type PluridServerService, type PluridServerTemplateConfiguration, type PluridStillerOptions, StillsGenerator as PluridStillsGenerator, type ServerRequest, PluridServer as default };
|
package/distribution/index.d.ts
CHANGED
|
@@ -1,6 +1,296 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { Server } from 'http';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { PluridPreserve, IsoMatcherRouteResult, PluridRoute, PluridRoutePlane, PluridRouterProperties } from '@plurid/plurid-data';
|
|
5
|
+
import { PluridReactComponent } from '@plurid/plurid-react';
|
|
6
|
+
import { Helmet } from 'react-helmet-async';
|
|
7
|
+
|
|
8
|
+
type PluridServerMiddleware = (request: express.Request, response: express.Response, next: express.NextFunction) => void;
|
|
9
|
+
type ServerRequest = express.Request & {
|
|
10
|
+
requestID: string;
|
|
11
|
+
requestTime: number;
|
|
12
|
+
};
|
|
13
|
+
type DebugLevels = 'none' | 'error' | 'warn' | 'info';
|
|
14
|
+
interface PluridServerOptions {
|
|
15
|
+
/** To be used for logging. Default `Plurid Server` */
|
|
16
|
+
serverName: string;
|
|
17
|
+
/**
|
|
18
|
+
* The hostname of the server exposed to the internet, e.g. `example.com`,
|
|
19
|
+
* to be used in plurid plane links.
|
|
20
|
+
*/
|
|
21
|
+
hostname: string;
|
|
22
|
+
/**
|
|
23
|
+
* To log or not to log to the console.
|
|
24
|
+
*/
|
|
25
|
+
quiet: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Debug levels.
|
|
28
|
+
*
|
|
29
|
+
* Production default: `error`.
|
|
30
|
+
* Development default: `info` and above.
|
|
31
|
+
*/
|
|
32
|
+
debug: DebugLevels;
|
|
33
|
+
/**
|
|
34
|
+
* Use `gzip` compression for the response. Default `true`.
|
|
35
|
+
*/
|
|
36
|
+
compression: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Open in browser at start.
|
|
39
|
+
*/
|
|
40
|
+
open: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Name of the directory where the files (server and client) are bundled.
|
|
43
|
+
*/
|
|
44
|
+
buildDirectory: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name of the directory where the assets files are bundled.
|
|
47
|
+
*/
|
|
48
|
+
assetsDirectory: string;
|
|
49
|
+
/**
|
|
50
|
+
* Directory of static assets (favicon, og-image, manifest, robots) served at
|
|
51
|
+
* the URL root `/`. Empty string (the default) resolves to
|
|
52
|
+
* `<buildDirectory>/public`; the mount is skipped if the directory does not
|
|
53
|
+
* exist, so apps without a public directory are unaffected. The framework
|
|
54
|
+
* points this at `source/public` during `plurid dev`.
|
|
55
|
+
*/
|
|
56
|
+
publicDirectory: string;
|
|
57
|
+
/**
|
|
58
|
+
* Default: `/gateway`.
|
|
59
|
+
*/
|
|
60
|
+
gatewayEndpoint: string;
|
|
61
|
+
/**
|
|
62
|
+
* Provide a `max-age` in milliseconds for http caching of the static serves.
|
|
63
|
+
* This can also be a string accepted by the `ms` module.
|
|
64
|
+
*
|
|
65
|
+
* Default: 0.
|
|
66
|
+
*/
|
|
67
|
+
staticCache: number | string;
|
|
68
|
+
/**
|
|
69
|
+
* Routes to be ignored when serving the application (`GET`).
|
|
70
|
+
*/
|
|
71
|
+
ignore: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Name of the directory where the stills are gathered.
|
|
74
|
+
*/
|
|
75
|
+
stillsDirectory: string;
|
|
76
|
+
stiller: PluridStillerOptions;
|
|
77
|
+
/**
|
|
78
|
+
* Install `SIGINT`/`SIGTERM` handlers that stop the server and call `process.exit`.
|
|
79
|
+
* Defaults to `true` (convenient for the CLI). Set to `false` when EMBEDDING the server
|
|
80
|
+
* in a host process you do not want it to terminate; then manage lifecycle via `stop()`.
|
|
81
|
+
*/
|
|
82
|
+
attachSignalHandlers: boolean;
|
|
83
|
+
}
|
|
84
|
+
type PluridServerPartialOptions = Partial<PluridServerOptions>;
|
|
85
|
+
interface PluridServerService<P = any, PP = any> {
|
|
86
|
+
name: string;
|
|
87
|
+
Provider: P;
|
|
88
|
+
properties?: PP;
|
|
89
|
+
}
|
|
90
|
+
interface PluridServerConfiguration {
|
|
91
|
+
routes: PluridRoute<PluridReactComponent>[];
|
|
92
|
+
planes?: PluridRoutePlane<PluridReactComponent>[];
|
|
93
|
+
preserves: PluridPreserveReact[];
|
|
94
|
+
helmet: Helmet;
|
|
95
|
+
styles?: string[];
|
|
96
|
+
middleware?: PluridServerMiddleware[];
|
|
97
|
+
exterior?: PluridReactComponent;
|
|
98
|
+
shell?: PluridReactComponent;
|
|
99
|
+
routerProperties?: Partial<PluridRouterProperties<PluridReactComponent>>;
|
|
100
|
+
/**
|
|
101
|
+
* Replace the internal plurid plane with a custom implementation.
|
|
102
|
+
*/
|
|
103
|
+
customPlane?: PluridReactComponent;
|
|
104
|
+
/**
|
|
105
|
+
* Services to be handled by the server.
|
|
106
|
+
*
|
|
107
|
+
* Supported: `GraphQL`, `Redux`, `Stripe`.
|
|
108
|
+
*/
|
|
109
|
+
services?: PluridServerService[];
|
|
110
|
+
options?: PluridServerPartialOptions;
|
|
111
|
+
template?: PluridServerTemplateConfiguration;
|
|
112
|
+
usePTTP?: boolean;
|
|
113
|
+
pttpHandler?: PTTPHandler;
|
|
114
|
+
elementqlEndpoint?: string;
|
|
115
|
+
}
|
|
116
|
+
type PTTPHandler = (path: string) => Promise<boolean>;
|
|
117
|
+
interface PluridServerTemplateConfiguration {
|
|
118
|
+
htmlLanguage?: string;
|
|
119
|
+
htmlAttributes?: Record<string, string>;
|
|
120
|
+
defaultStyle?: string;
|
|
121
|
+
headScripts?: string[];
|
|
122
|
+
bodyScripts?: string[];
|
|
123
|
+
/**
|
|
124
|
+
* The JavaScript vendor filepath to inject in the HTML template.
|
|
125
|
+
* Default `'/vendor.js'`.
|
|
126
|
+
*
|
|
127
|
+
* A CDN link can be used for better caching.
|
|
128
|
+
*/
|
|
129
|
+
vendorScriptSource?: string;
|
|
130
|
+
/**
|
|
131
|
+
* The JavaScript filename to inject in the HTML template.
|
|
132
|
+
*/
|
|
133
|
+
mainScriptSource?: string;
|
|
134
|
+
bodyAttributes?: Record<string, string>;
|
|
135
|
+
/**
|
|
136
|
+
* The ID of the root element in the HTML template.
|
|
137
|
+
*/
|
|
138
|
+
root?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Global variable name to be attached to window on the server-side
|
|
141
|
+
* to preload plurid metastate.
|
|
142
|
+
*
|
|
143
|
+
* Default: `__PRELOADED_PLURID_METASTATE__`
|
|
144
|
+
*/
|
|
145
|
+
defaultPreloadedPluridMetastate?: string;
|
|
146
|
+
minify?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Favicon links injected into `<head>`. A bare string is the primary icon
|
|
149
|
+
* (`rel="icon"`); the object expands to icon / apple-touch-icon / sized /
|
|
150
|
+
* mask-icon links plus a `theme-color` meta. Paths resolve against the served
|
|
151
|
+
* public directory (see `PluridServerOptions.publicDirectory`).
|
|
152
|
+
*/
|
|
153
|
+
favicon?: string | {
|
|
154
|
+
icon?: string;
|
|
155
|
+
apple?: string;
|
|
156
|
+
sizes?: Record<string, string>;
|
|
157
|
+
maskIcon?: string;
|
|
158
|
+
themeColor?: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Web app manifest href, injected as `<link rel="manifest">`.
|
|
162
|
+
*/
|
|
163
|
+
manifest?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Static `<head>` metadata injected AHEAD of the react-helmet-async output,
|
|
166
|
+
* so per-route `<Helmet>` tags still override these defaults.
|
|
167
|
+
*/
|
|
168
|
+
head?: {
|
|
169
|
+
title?: string;
|
|
170
|
+
description?: string;
|
|
171
|
+
meta?: Array<{
|
|
172
|
+
name?: string;
|
|
173
|
+
property?: string;
|
|
174
|
+
content: string;
|
|
175
|
+
}>;
|
|
176
|
+
links?: Array<{
|
|
177
|
+
rel: string;
|
|
178
|
+
href: string;
|
|
179
|
+
}>;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Override the built-in 500 error page HTML (sent on a render failure).
|
|
183
|
+
*/
|
|
184
|
+
errorHtml?: string;
|
|
185
|
+
}
|
|
186
|
+
interface PluridStillerOptions {
|
|
187
|
+
/**
|
|
188
|
+
* Recommended: `'networkidle0'` | `'networkidle2'` | `'load'`.
|
|
189
|
+
*
|
|
190
|
+
* Default: `'networkidle0'`.
|
|
191
|
+
*/
|
|
192
|
+
waitUntil: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
|
|
193
|
+
/**
|
|
194
|
+
* Maximum navigation time in milliseconds, pass 0 to disable timeout.
|
|
195
|
+
*
|
|
196
|
+
* Default: 30000.
|
|
197
|
+
*/
|
|
198
|
+
timeout: number;
|
|
199
|
+
/**
|
|
200
|
+
* Routes to be ignored by the stilling process.
|
|
201
|
+
*/
|
|
202
|
+
ignore: string[];
|
|
203
|
+
}
|
|
204
|
+
type PluridPreserveReact = PluridPreserve<IsoMatcherRouteResult<PluridReactComponent<any>> | undefined, express.Request, express.Response>;
|
|
205
|
+
interface PluridLiveServerOptions {
|
|
206
|
+
server: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface StillsGeneratorOptions {
|
|
210
|
+
server: string;
|
|
211
|
+
build: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
declare class PluridServer {
|
|
215
|
+
private routes;
|
|
216
|
+
private planes;
|
|
217
|
+
private preserves;
|
|
218
|
+
private helmet;
|
|
219
|
+
private styles;
|
|
220
|
+
private middleware;
|
|
221
|
+
private exterior;
|
|
222
|
+
private shell;
|
|
223
|
+
private routerProperties;
|
|
224
|
+
private services;
|
|
225
|
+
private options;
|
|
226
|
+
private template;
|
|
227
|
+
usePTTP: boolean;
|
|
228
|
+
private pttpHandler;
|
|
229
|
+
private elementqlEndpoint;
|
|
230
|
+
private serverApplication;
|
|
231
|
+
private server;
|
|
232
|
+
private port;
|
|
233
|
+
private stills;
|
|
234
|
+
private isoMatcher;
|
|
235
|
+
constructor(configuration: PluridServerConfiguration);
|
|
236
|
+
private handleProcessSignal;
|
|
237
|
+
private signalHandlersAttached;
|
|
238
|
+
attachSignalHandlers(): void;
|
|
239
|
+
detachSignalHandlers(): void;
|
|
240
|
+
static analysis(pluridServer: PluridServer): {
|
|
241
|
+
routes: PluridRoute<PluridReactComponent, any>[];
|
|
242
|
+
options: PluridServerOptions;
|
|
243
|
+
};
|
|
244
|
+
start(port?: string | number): Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
245
|
+
stop(): void;
|
|
246
|
+
handle(): {
|
|
247
|
+
post: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
248
|
+
patch: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
249
|
+
put: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
250
|
+
delete: (path: string, ...handlers: express.RequestHandler[]) => express.Express;
|
|
251
|
+
};
|
|
252
|
+
instance(): express.Express;
|
|
253
|
+
private handleEndpoints;
|
|
254
|
+
private handleGetRequest;
|
|
255
|
+
private handlePTTPRequest;
|
|
256
|
+
private ignoreGetRequest;
|
|
257
|
+
private resolveMatchingPath;
|
|
258
|
+
private resolvePreserve;
|
|
259
|
+
private resolvePreserveAfterServe;
|
|
260
|
+
private handleGateway;
|
|
261
|
+
private renderApplication;
|
|
262
|
+
/**
|
|
263
|
+
* Build the static `<head>` markup from the template config (favicon set,
|
|
264
|
+
* manifest, default title / meta / links). Returns an empty string when none
|
|
265
|
+
* are configured, so the head is byte-identical to before for existing apps.
|
|
266
|
+
*/
|
|
267
|
+
private buildStaticHead;
|
|
268
|
+
private getContentAndStyles;
|
|
269
|
+
private computeRequestTime;
|
|
270
|
+
private handleOptions;
|
|
271
|
+
private configureServer;
|
|
272
|
+
private loadMiddleware;
|
|
273
|
+
private open;
|
|
274
|
+
private debugAllows;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
declare class LiveServer {
|
|
278
|
+
private options;
|
|
279
|
+
private expressServer;
|
|
280
|
+
private httpServer;
|
|
281
|
+
private sockets;
|
|
282
|
+
constructor(options?: Partial<PluridLiveServerOptions>);
|
|
283
|
+
private resolveOptions;
|
|
284
|
+
private setupExpressServer;
|
|
285
|
+
private setupHttpServer;
|
|
286
|
+
start(): never;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare class StillsGenerator {
|
|
290
|
+
private options;
|
|
291
|
+
constructor(options?: Partial<StillsGeneratorOptions>);
|
|
292
|
+
resolveOptions(options?: Partial<StillsGeneratorOptions>): StillsGeneratorOptions;
|
|
293
|
+
initialize(): Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export { type DebugLevels, type PTTPHandler, LiveServer as PluridLiveServer, type PluridLiveServerOptions, type PluridPreserveReact, type PluridServerConfiguration, type PluridServerMiddleware, type PluridServerOptions, type PluridServerPartialOptions, type PluridServerService, type PluridServerTemplateConfiguration, type PluridStillerOptions, StillsGenerator as PluridStillsGenerator, type ServerRequest, PluridServer as default };
|