@canonical/react-ssr 0.27.1-experimental.0 → 0.28.0
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 +74 -27
- package/dist/esm/bin/serve-bun.js +77 -0
- package/dist/esm/bin/serve-bun.js.map +1 -0
- package/dist/esm/bin/serve-express.js +19 -36
- package/dist/esm/bin/serve-express.js.map +1 -1
- package/dist/esm/lib/adapter/index.js +1 -1
- package/dist/esm/lib/adapter/index.js.map +1 -1
- package/dist/esm/lib/adapter/mime.js +7 -0
- package/dist/esm/lib/adapter/mime.js.map +1 -1
- package/dist/esm/lib/renderer/JSXRenderer.js +2 -0
- package/dist/esm/lib/renderer/JSXRenderer.js.map +1 -1
- package/dist/esm/lib/renderer/SitemapRenderer.js +2 -0
- package/dist/esm/lib/renderer/SitemapRenderer.js.map +1 -1
- package/dist/esm/lib/server/StaticMount.js +2 -0
- package/dist/esm/lib/server/StaticMount.js.map +1 -0
- package/dist/esm/lib/server/getRequestUrl.js +41 -0
- package/dist/esm/lib/server/getRequestUrl.js.map +1 -0
- package/dist/esm/lib/server/index.js +6 -0
- package/dist/esm/lib/server/index.js.map +1 -1
- package/dist/esm/lib/server/matchStaticRoute.js +14 -0
- package/dist/esm/lib/server/matchStaticRoute.js.map +1 -0
- package/dist/esm/lib/server/parseStaticPair.js +20 -0
- package/dist/esm/lib/server/parseStaticPair.js.map +1 -0
- package/dist/esm/lib/server/resolvePort.js +29 -0
- package/dist/esm/lib/server/resolvePort.js.map +1 -0
- package/dist/esm/lib/server/resolveStaticFile.js +61 -0
- package/dist/esm/lib/server/resolveStaticFile.js.map +1 -0
- package/dist/esm/lib/server/serveStream.js +1 -1
- package/dist/esm/lib/server/serveStream.js.map +1 -1
- package/dist/esm/lib/server/viteFetchMiddleware.js +152 -0
- package/dist/esm/lib/server/viteFetchMiddleware.js.map +1 -0
- package/dist/types/bin/serve-bun.d.ts +25 -0
- package/dist/types/bin/serve-bun.d.ts.map +1 -0
- package/dist/types/bin/serve-express.d.ts +6 -3
- package/dist/types/bin/serve-express.d.ts.map +1 -1
- package/dist/types/lib/adapter/index.d.ts +1 -1
- package/dist/types/lib/adapter/index.d.ts.map +1 -1
- package/dist/types/lib/adapter/mime.d.ts +7 -0
- package/dist/types/lib/adapter/mime.d.ts.map +1 -1
- package/dist/types/lib/adapter/types.d.ts +8 -10
- package/dist/types/lib/adapter/types.d.ts.map +1 -1
- package/dist/types/lib/renderer/JSXRenderer.d.ts +2 -0
- package/dist/types/lib/renderer/JSXRenderer.d.ts.map +1 -1
- package/dist/types/lib/renderer/SitemapRenderer.d.ts +2 -0
- package/dist/types/lib/renderer/SitemapRenderer.d.ts.map +1 -1
- package/dist/types/lib/server/StaticMount.d.ts +11 -0
- package/dist/types/lib/server/StaticMount.d.ts.map +1 -0
- package/dist/types/lib/server/getRequestUrl.d.ts +29 -0
- package/dist/types/lib/server/getRequestUrl.d.ts.map +1 -0
- package/dist/types/lib/server/index.d.ts +7 -0
- package/dist/types/lib/server/index.d.ts.map +1 -1
- package/dist/types/lib/server/matchStaticRoute.d.ts +12 -0
- package/dist/types/lib/server/matchStaticRoute.d.ts.map +1 -0
- package/dist/types/lib/server/parseStaticPair.d.ts +12 -0
- package/dist/types/lib/server/parseStaticPair.d.ts.map +1 -0
- package/dist/types/lib/server/resolvePort.d.ts +20 -0
- package/dist/types/lib/server/resolvePort.d.ts.map +1 -0
- package/dist/types/lib/server/resolveStaticFile.d.ts +20 -0
- package/dist/types/lib/server/resolveStaticFile.d.ts.map +1 -0
- package/dist/types/lib/server/serveStream.d.ts +1 -0
- package/dist/types/lib/server/serveStream.d.ts.map +1 -1
- package/dist/types/lib/server/viteFetchMiddleware.d.ts +81 -0
- package/dist/types/lib/server/viteFetchMiddleware.d.ts.map +1 -0
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -33,6 +33,35 @@ The rest of the page is then streamed to the client as it is rendered on the ser
|
|
|
33
33
|
|
|
34
34
|
This is accomplished by using `JSXRenderer.renderToStream()`.
|
|
35
35
|
|
|
36
|
+
## Dev vs production SSR
|
|
37
|
+
|
|
38
|
+
The renderer is the invariant of every SSR setup: it takes an `htmlString`
|
|
39
|
+
shell, extracts the `<head>` `<script>`/`<link>` tags, and injects them into
|
|
40
|
+
the streamed output. **It never reads from disk and never cares which mode you
|
|
41
|
+
run in.** What changes between development and production is only two things —
|
|
42
|
+
*where the HTML shell comes from* and *how client JS/CSS reach the browser*:
|
|
43
|
+
|
|
44
|
+
| | **Development** (transform) | **Production** (compiled) |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| HTML shell | root `index.html` → `vite.transformIndexHtml()` | built `dist/client/index.html` (hashed tags baked in) |
|
|
47
|
+
| Server entry | `vite.ssrLoadModule()` (TypeScript, on the fly) | compiled `dist/server` bundle |
|
|
48
|
+
| Client JS/CSS | served by Vite's middleware (source modules, HMR) | static files from `dist/client` |
|
|
49
|
+
| Renderer | **same `JSXRenderer`** | **same `JSXRenderer`** |
|
|
50
|
+
|
|
51
|
+
This means a dev SSR server and a production SSR server are *deliberately
|
|
52
|
+
different* — the dev server transforms source on the fly (with HMR); the
|
|
53
|
+
production server serves a pre-built client and a compiled renderer. Both feed
|
|
54
|
+
the same renderer; only the shell and asset-serving differ.
|
|
55
|
+
|
|
56
|
+
In development you mount Vite's middleware so that asset, module, and HMR
|
|
57
|
+
requests (`/@vite/client`, `/src/**`, `/@id/**`, `/@fs/**`, `/@react-refresh`,
|
|
58
|
+
`/node_modules/.vite/**`) are handled by Vite, and only page routes reach the
|
|
59
|
+
renderer. With Express this is `app.use(vite.middlewares)`. For `fetch`-style
|
|
60
|
+
servers (Bun, Deno, Workers) use [`viteFetchMiddleware`](#bun-server) — it
|
|
61
|
+
bridges Vite's connect middleware into a `Request → Response` handler. Without
|
|
62
|
+
it, those asset requests get server-rendered as the HTML page with the wrong
|
|
63
|
+
`Content-Type`, the browser blocks the modules, and the page never hydrates.
|
|
64
|
+
|
|
36
65
|
## Express Server
|
|
37
66
|
|
|
38
67
|
Create a renderer that wraps your server entry component:
|
|
@@ -72,46 +101,64 @@ node dist/server/server.js
|
|
|
72
101
|
|
|
73
102
|
## Bun Server
|
|
74
103
|
|
|
75
|
-
|
|
104
|
+
`Bun.serve` works with a Web `Request`/`Response` `fetch` handler, so it cannot
|
|
105
|
+
mount Vite's connect middleware directly. `viteFetchMiddleware` bridges the two:
|
|
106
|
+
it runs a `Request` through `vite.middlewares` and returns a `Response` if Vite
|
|
107
|
+
handled it (assets, modules, HMR) or `null` for page routes you should render.
|
|
76
108
|
|
|
77
109
|
```ts
|
|
78
|
-
// src/
|
|
79
|
-
import
|
|
80
|
-
import {
|
|
110
|
+
// src/server/server.bun.ts — development
|
|
111
|
+
import { JSXRenderer } from "@canonical/react-ssr/renderer";
|
|
112
|
+
import { viteFetchMiddleware } from "@canonical/react-ssr/server";
|
|
113
|
+
import { createServer as createViteServer } from "vite";
|
|
114
|
+
import fs from "node:fs";
|
|
115
|
+
|
|
116
|
+
const vite = await createViteServer({
|
|
117
|
+
server: { middlewareMode: true },
|
|
118
|
+
appType: "custom",
|
|
119
|
+
});
|
|
120
|
+
const handleAsset = viteFetchMiddleware(vite);
|
|
81
121
|
|
|
82
122
|
Bun.serve({
|
|
83
|
-
port:
|
|
123
|
+
port: 5174,
|
|
84
124
|
async fetch(req) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (url.pathname.startsWith("/assets")) {
|
|
89
|
-
return new Response(Bun.file(`dist/client${url.pathname}`));
|
|
90
|
-
}
|
|
125
|
+
// Vite handles /@vite/client, /src/**, CSS, HMR; null → page route → SSR.
|
|
126
|
+
const asset = await handleAsset(req);
|
|
127
|
+
if (asset) return asset;
|
|
91
128
|
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
129
|
+
const url = new URL(req.url);
|
|
130
|
+
const html = await vite.transformIndexHtml(
|
|
131
|
+
url.pathname + url.search,
|
|
132
|
+
fs.readFileSync("index.html", "utf-8"),
|
|
133
|
+
);
|
|
134
|
+
const { default: EntryServer } = await vite.ssrLoadModule(
|
|
135
|
+
"/src/server/entry.tsx",
|
|
136
|
+
);
|
|
137
|
+
const renderer = new JSXRenderer(
|
|
138
|
+
EntryServer,
|
|
139
|
+
{ url: url.pathname + url.search },
|
|
140
|
+
{ htmlString: html },
|
|
141
|
+
);
|
|
142
|
+
return new Response(await renderer.renderToReadableStream(req.signal), {
|
|
143
|
+
status: renderer.statusCode,
|
|
96
144
|
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
97
145
|
});
|
|
98
146
|
},
|
|
99
147
|
});
|
|
100
|
-
|
|
101
|
-
function pipeToIterable(pipe: (dest: NodeJS.WritableStream) => void) {
|
|
102
|
-
const { Readable } = require("node:stream");
|
|
103
|
-
const passthrough = new (require("node:stream").PassThrough)();
|
|
104
|
-
pipe(passthrough);
|
|
105
|
-
return passthrough;
|
|
106
|
-
}
|
|
107
148
|
```
|
|
108
149
|
|
|
109
|
-
|
|
150
|
+
`viteFetchMiddleware` depends only on `node:http` and Web globals — no Bun APIs
|
|
151
|
+
— so it works under any `fetch`-style runtime (Bun, Deno, Workers, Node's own
|
|
152
|
+
`fetch` servers). The single Bun-specific call (`Bun.serve`) stays in your app.
|
|
110
153
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
154
|
+
For **production**, you do not run Vite at all. Build the client and a compiled
|
|
155
|
+
renderer, then serve the built output with the `serve-bun` bin (static assets +
|
|
156
|
+
your renderer factory):
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
vite build --ssrManifest --outDir dist/client
|
|
160
|
+
vite build --ssr src/server/renderer.tsx --outDir dist/server
|
|
161
|
+
serve-bun dist/server/renderer.js --static assets:dist/client/assets
|
|
115
162
|
```
|
|
116
163
|
|
|
117
164
|
## Entry Points
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Standalone Bun server for serving an SSR application with stream rendering.
|
|
4
|
+
*
|
|
5
|
+
* Uses `Bun.serve()` for the HTTP layer and `Bun.file()` for zero-copy static
|
|
6
|
+
* file serving. The renderer module must default-export a factory that accepts a
|
|
7
|
+
* `Request` and returns a renderer with `renderToReadableStream`.
|
|
8
|
+
*
|
|
9
|
+
* Argument parsing, port resolution, and static-file matching live in
|
|
10
|
+
* `@canonical/react-ssr/server` (covered by unit tests); this bin is the thin
|
|
11
|
+
* Bun-specific shell around them.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```sh
|
|
15
|
+
* # Single static directory
|
|
16
|
+
* serve-bun dist/server/renderer.js --static assets:dist/client/assets
|
|
17
|
+
*
|
|
18
|
+
* # Multiple static directories, custom port
|
|
19
|
+
* serve-bun dist/server/renderer.js -p 3000 \
|
|
20
|
+
* --static assets:dist/client/assets \
|
|
21
|
+
* --static public:dist/client/public
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { parseArgs } from "node:util";
|
|
26
|
+
import { parseStaticPair, resolvePort, resolveStaticFile, } from "@canonical/react-ssr/server";
|
|
27
|
+
const { values, positionals } = parseArgs({
|
|
28
|
+
args: process.argv.slice(2),
|
|
29
|
+
options: {
|
|
30
|
+
port: { type: "string", short: "p" },
|
|
31
|
+
static: {
|
|
32
|
+
type: "string",
|
|
33
|
+
short: "s",
|
|
34
|
+
multiple: true,
|
|
35
|
+
default: ["assets:dist/client/assets"],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
strict: true,
|
|
39
|
+
allowPositionals: true,
|
|
40
|
+
});
|
|
41
|
+
const rendererArg = positionals[0];
|
|
42
|
+
if (!rendererArg) {
|
|
43
|
+
console.error("Usage: serve-bun <renderer-path> [--static route:path ...] [-p port]");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const port = resolvePort(values.port, process.env.PORT);
|
|
47
|
+
const rendererFilePath = path.join(process.cwd(), rendererArg);
|
|
48
|
+
const createRenderer = await import(rendererFilePath).then((m) => m.default);
|
|
49
|
+
if (typeof createRenderer !== "function") {
|
|
50
|
+
throw new Error("Renderer module must default-export a factory function (req: Request) => Renderer.");
|
|
51
|
+
}
|
|
52
|
+
const staticMounts = (values.static ?? []).map((pair) => parseStaticPair(pair));
|
|
53
|
+
Bun.serve({
|
|
54
|
+
port,
|
|
55
|
+
async fetch(req) {
|
|
56
|
+
const url = new URL(req.url);
|
|
57
|
+
for (const mount of staticMounts) {
|
|
58
|
+
const filePath = resolveStaticFile(url.pathname, mount);
|
|
59
|
+
if (filePath) {
|
|
60
|
+
const file = Bun.file(filePath);
|
|
61
|
+
if (await file.exists()) {
|
|
62
|
+
return new Response(file);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const renderer = createRenderer(req);
|
|
67
|
+
const stream = await renderer.renderToReadableStream(req.signal);
|
|
68
|
+
return new Response(stream, {
|
|
69
|
+
status: renderer.statusCode,
|
|
70
|
+
headers: {
|
|
71
|
+
"Content-Type": renderer.contentType ?? "text/html; charset=utf-8",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
console.log(`Server started on http://localhost:${port}/`);
|
|
77
|
+
//# sourceMappingURL=serve-bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-bun.js","sourceRoot":"","sources":["../../../src/bin/serve-bun.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,eAAe,EACf,WAAW,EACX,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAerC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACxC,IAAI,EAAE,OAA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,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE7B,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAChC,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;oBACxB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC1B,MAAM,EAAE,QAAQ,CAAC,UAAU;YAC3B,OAAO,EAAE;gBACP,cAAc,EAAE,QAAQ,CAAC,WAAW,IAAI,0BAA0B;aACnE;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,GAAG,CAAC,CAAC"}
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Standalone Express server for serving an SSR application.
|
|
4
4
|
*
|
|
5
|
-
* Dynamically imports a renderer module that exports a factory
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Dynamically imports a renderer module that default-exports a factory. The
|
|
6
|
+
* factory receives a Node `IncomingMessage` and returns a renderer. Supports
|
|
7
|
+
* both streaming (`--streaming`) and string rendering modes.
|
|
8
|
+
*
|
|
9
|
+
* Argument parsing and port resolution live in `@canonical/react-ssr/server`
|
|
10
|
+
* (covered by unit tests); this bin is the thin Express-specific shell.
|
|
8
11
|
*
|
|
9
12
|
* @example
|
|
10
13
|
* ```sh
|
|
@@ -22,54 +25,34 @@
|
|
|
22
25
|
*/
|
|
23
26
|
import path from "node:path";
|
|
24
27
|
import { parseArgs } from "node:util";
|
|
28
|
+
// Import via the public self-referential path (resolved through "exports" to
|
|
29
|
+
// dist/esm) rather than the "#server" internal alias, which points at the
|
|
30
|
+
// TypeScript source — the serve-express bin runs under Node (its shebang),
|
|
31
|
+
// which cannot load .ts.
|
|
32
|
+
import { parseStaticPair, resolvePort, serveStream, serveString, } from "@canonical/react-ssr/server";
|
|
25
33
|
import express from "express";
|
|
26
|
-
import { serveStream } from "#server";
|
|
27
|
-
/**
|
|
28
|
-
* Parse a `route:filepath` string into its constituent parts.
|
|
29
|
-
*
|
|
30
|
-
* @param pair - A string in the format `"route:filepath"`, e.g. `"assets:dist/client/assets"`.
|
|
31
|
-
* @returns An object with the route prefix and the absolute filesystem path.
|
|
32
|
-
*/
|
|
33
|
-
function parseStaticPair(pair) {
|
|
34
|
-
const separatorIndex = pair.indexOf(":");
|
|
35
|
-
if (separatorIndex === -1) {
|
|
36
|
-
return { route: `/${pair}`, dir: path.join(process.cwd(), pair) };
|
|
37
|
-
}
|
|
38
|
-
const route = pair.slice(0, separatorIndex);
|
|
39
|
-
const filepath = pair.slice(separatorIndex + 1);
|
|
40
|
-
return {
|
|
41
|
-
route: `/${route}`,
|
|
42
|
-
dir: path.join(process.cwd(), filepath),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
34
|
const { values, positionals } = parseArgs({
|
|
46
35
|
args: process.argv.slice(2),
|
|
47
36
|
options: {
|
|
48
|
-
port: {
|
|
49
|
-
type: "string",
|
|
50
|
-
alias: "p",
|
|
51
|
-
default: "5173",
|
|
52
|
-
},
|
|
37
|
+
port: { type: "string", short: "p" },
|
|
53
38
|
static: {
|
|
54
39
|
type: "string",
|
|
55
|
-
|
|
40
|
+
short: "s",
|
|
56
41
|
multiple: true,
|
|
57
42
|
default: ["assets:dist/client/assets"],
|
|
58
43
|
},
|
|
59
|
-
streaming: {
|
|
60
|
-
type: "boolean",
|
|
61
|
-
default: false,
|
|
62
|
-
},
|
|
44
|
+
streaming: { type: "boolean", default: false },
|
|
63
45
|
},
|
|
64
46
|
strict: true,
|
|
65
47
|
allowPositionals: true,
|
|
66
48
|
});
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
if (!rendererFilePath) {
|
|
49
|
+
const rendererArg = positionals[0];
|
|
50
|
+
if (!rendererArg) {
|
|
70
51
|
console.error("Usage: serve-express <renderer-path> [--static route:path ...] [--streaming] [-p port]");
|
|
71
52
|
process.exit(1);
|
|
72
53
|
}
|
|
54
|
+
const port = resolvePort(values.port, process.env.PORT);
|
|
55
|
+
const rendererFilePath = path.join(process.cwd(), rendererArg);
|
|
73
56
|
const createRenderer = await import(rendererFilePath).then((m) => m.default);
|
|
74
57
|
if (typeof createRenderer !== "function") {
|
|
75
58
|
throw new Error("Renderer module must default-export a factory function (req) => Renderer.");
|
|
@@ -79,7 +62,7 @@ for (const pair of values.static ?? []) {
|
|
|
79
62
|
const { route, dir } = parseStaticPair(pair);
|
|
80
63
|
app.use(route, express.static(dir));
|
|
81
64
|
}
|
|
82
|
-
app.use(serveStream(createRenderer));
|
|
65
|
+
app.use(values.streaming ? serveStream(createRenderer) : serveString(createRenderer));
|
|
83
66
|
app.listen(port, () => {
|
|
84
67
|
console.log(`Server started on http://localhost:${port}/`);
|
|
85
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-express.js","sourceRoot":"","sources":["../../../src/bin/serve-express.ts"],"names":[],"mappings":";AAEA
|
|
1
|
+
{"version":3,"file":"serve-express.js","sourceRoot":"","sources":["../../../src/bin/serve-express.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,6EAA6E;AAC7E,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CAAC;IACzC,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;IACvC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAC7C,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,GAAG,CAAC,GAAG,CACL,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC,CAC7E,CAAC;AAEF,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { buildCacheControl, getMimeType, matchPattern } from "./mime.js";
|
|
1
|
+
export { buildCacheControl, getMimeType, IMMUTABLE_ASSET_CACHE_CONTROL, matchPattern, } from "./mime.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,6BAA6B,EAC7B,YAAY,GACb,MAAM,WAAW,CAAC"}
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
*
|
|
8
8
|
* No external dependencies — the lookup is a plain record.
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* `Cache-Control` value for immutable, content-hashed static assets (e.g. Vite
|
|
12
|
+
* build output). One year, immutable — the canonical policy every adapter
|
|
13
|
+
* applies when serving fingerprinted assets. Centralised here so the three
|
|
14
|
+
* deployment adapters cannot drift.
|
|
15
|
+
*/
|
|
16
|
+
export const IMMUTABLE_ASSET_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
10
17
|
const MIME_TYPES = {
|
|
11
18
|
".html": "text/html; charset=utf-8",
|
|
12
19
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/lib/adapter/mime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,UAAU,GAA2B;IACzC,OAAO,EAAE,0BAA0B;IACnC,KAAK,EAAE,uCAAuC;IAC9C,MAAM,EAAE,uCAAuC;IAC/C,MAAM,EAAE,yBAAyB;IACjC,OAAO,EAAE,iCAAiC;IAC1C,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,cAAc;IACtB,OAAO,EAAE,WAAW;IACpB,QAAQ,EAAE,YAAY;IACtB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,2BAA2B;IACnC,MAAM,EAAE,gCAAgC;IACxC,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,iCAAiC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,QAAQ,KAAK,CAAC,CAAC;QAAE,OAAO,0BAA0B,CAAC;IACvD,MAAM,GAAG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K,CAAC,OAAO,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACnE,IAAI,KAAK,CAAC,oBAAoB,IAAI,IAAI;QACpC,KAAK,CAAC,IAAI,CAAC,0BAA0B,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,QAAgB;IAC5D,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,QAAQ,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,QAAQ,KAAK,OAAO,CAAC;AAC9B,CAAC"}
|
|
@@ -63,6 +63,8 @@ export default class JSXRenderer {
|
|
|
63
63
|
* `renderToString`) or after awaiting `statusReady` (for `renderToPipeableStream`).
|
|
64
64
|
*/
|
|
65
65
|
statusCode = 200;
|
|
66
|
+
/** MIME type of the rendered output, for the consumer's `Content-Type` header. */
|
|
67
|
+
contentType = "text/html; charset=utf-8";
|
|
66
68
|
/**
|
|
67
69
|
* Resolves when `statusCode` is determined.
|
|
68
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSXRenderer.js","sourceRoot":"","sources":["../../../../src/lib/renderer/JSXRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,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BACR,kBAAkB,EAAE,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;IAC1D,CAAC,CAAC;IAEF;;;;;;;;;;;;OAYG;IACH,cAAc,GAAG,GAAW,EAAE;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;CACH"}
|
|
@@ -37,6 +37,8 @@ export default class SitemapRenderer {
|
|
|
37
37
|
* error handler decides the status code for unexpected failures.
|
|
38
38
|
*/
|
|
39
39
|
statusCode = 200;
|
|
40
|
+
/** MIME type of the rendered output, for the consumer's `Content-Type` header. */
|
|
41
|
+
contentType = "application/xml; charset=utf-8";
|
|
40
42
|
/**
|
|
41
43
|
* Resolves when `statusCode` is determined.
|
|
42
44
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SitemapRenderer.js","sourceRoot":"","sources":["../../../../src/lib/renderer/SitemapRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"SitemapRenderer.js","sourceRoot":"","sources":["../../../../src/lib/renderer/SitemapRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ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AAK,CAAC;QAEpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YAC9C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,CAAkC,WAAc,EAAE,EAAE,CACxD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC;YAC5B,KAAK,EAAE,GAAG,EAAE;gBACV,OAAO,GAAG,IAAI,CAAC;gBACf,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,cAAc,GAAG,KAAK,IAAqB,EAAE;QAC3C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticMount.js","sourceRoot":"","sources":["../../../../src/lib/server/StaticMount.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the request path (`pathname` + `search`) from either a Web `Request`
|
|
3
|
+
* or a Node `IncomingMessage`.
|
|
4
|
+
*
|
|
5
|
+
* The `serve-bun` and `serve-express` bins call a renderer factory with
|
|
6
|
+
* different request shapes — `serve-bun` passes a Web `Request` (whose `url` is
|
|
7
|
+
* absolute, e.g. `https://host/a/b?x=1`), while `serve-express` (via
|
|
8
|
+
* `serveStream`) passes a Node `IncomingMessage` (whose `url` is already a path,
|
|
9
|
+
* e.g. `/a/b?x=1`). A renderer factory that needs the URL for routing must
|
|
10
|
+
* handle both; this helper normalises them to a single path string.
|
|
11
|
+
*
|
|
12
|
+
* @param request - A Web `Request` or a Node `IncomingMessage`.
|
|
13
|
+
* @returns The request path including query string, e.g. `/a/b?x=1`. Defaults to
|
|
14
|
+
* `/` when no URL is present.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { JSXRenderer } from "@canonical/react-ssr/renderer";
|
|
19
|
+
* import { getRequestUrl } from "@canonical/react-ssr/server";
|
|
20
|
+
*
|
|
21
|
+
* export default function createRenderer(request: Request | IncomingMessage) {
|
|
22
|
+
* const url = getRequestUrl(request);
|
|
23
|
+
* return new JSXRenderer(EntryServer, { url }, { htmlString });
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function getRequestUrl(request) {
|
|
28
|
+
const raw = request.url;
|
|
29
|
+
if (!raw)
|
|
30
|
+
return "/";
|
|
31
|
+
// A Web Request `url` is absolute (parses as a URL); a Node IncomingMessage
|
|
32
|
+
// `url` is already a path (relative → URL parsing throws).
|
|
33
|
+
try {
|
|
34
|
+
const parsed = new URL(raw);
|
|
35
|
+
return parsed.pathname + parsed.search;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return raw;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=getRequestUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestUrl.js","sourceRoot":"","sources":["../../../../src/lib/server/getRequestUrl.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,OAAkC;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IACrB,4EAA4E;IAC5E,2DAA2D;IAC3D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export { getRequestUrl } from "./getRequestUrl.js";
|
|
2
|
+
export { matchStaticRoute } from "./matchStaticRoute.js";
|
|
3
|
+
export { parseStaticPair } from "./parseStaticPair.js";
|
|
4
|
+
export { resolvePort } from "./resolvePort.js";
|
|
5
|
+
export { resolveStaticFile } from "./resolveStaticFile.js";
|
|
1
6
|
export { serveStream } from "./serveStream.js";
|
|
2
7
|
export { serveString } from "./serveString.js";
|
|
8
|
+
export { viteFetchMiddleware, } from "./viteFetchMiddleware.js";
|
|
3
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does `pathname` fall under `route`, matched on a path-segment boundary?
|
|
3
|
+
*
|
|
4
|
+
* `/assets` matches `/assets` and `/assets/x` but NOT `/assetsfoo/x` — a plain
|
|
5
|
+
* `startsWith` would wrongly match the latter. The root mount `/` matches every
|
|
6
|
+
* path, so a single `:dir` mount can serve a whole built client directory.
|
|
7
|
+
*
|
|
8
|
+
* @param pathname - The request pathname (no query string).
|
|
9
|
+
* @param route - The mount's route prefix.
|
|
10
|
+
*/
|
|
11
|
+
export function matchStaticRoute(pathname, route) {
|
|
12
|
+
return (route === "/" || pathname === route || pathname.startsWith(`${route}/`));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=matchStaticRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchStaticRoute.js","sourceRoot":"","sources":["../../../../src/lib/server/matchStaticRoute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,KAAa;IAC9D,OAAO,CACL,KAAK,KAAK,GAAG,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,KAAK,GAAG,CAAC,CACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a `route:filepath` pair (e.g. `"assets:dist/client/assets"`) into a
|
|
4
|
+
* {@link StaticMount}. With no separator the whole string is both the route and
|
|
5
|
+
* the (cwd-relative) directory; an empty route (`":dist/client"`) is the root
|
|
6
|
+
* mount. The directory is resolved against `cwd`.
|
|
7
|
+
*
|
|
8
|
+
* @param pair - A `"route:filepath"` or bare `"name"` string.
|
|
9
|
+
* @param cwd - Base directory for resolving the filepath (default `process.cwd()`).
|
|
10
|
+
*/
|
|
11
|
+
export function parseStaticPair(pair, cwd = process.cwd()) {
|
|
12
|
+
const separatorIndex = pair.indexOf(":");
|
|
13
|
+
if (separatorIndex === -1) {
|
|
14
|
+
return { route: `/${pair}`, dir: path.join(cwd, pair) };
|
|
15
|
+
}
|
|
16
|
+
const route = pair.slice(0, separatorIndex);
|
|
17
|
+
const filepath = pair.slice(separatorIndex + 1);
|
|
18
|
+
return { route: `/${route}`, dir: path.join(cwd, filepath) };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=parseStaticPair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseStaticPair.js","sourceRoot":"","sources":["../../../../src/lib/server/parseStaticPair.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;IAC1D,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IAChD,OAAO,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the port a `serve-*` bin should listen on.
|
|
3
|
+
*
|
|
4
|
+
* Precedence: an explicit `--port`/`-p` flag, then the `PORT` env var, then the
|
|
5
|
+
* default `5174`. A value that is *present but not a valid TCP port* (non-integer
|
|
6
|
+
* or outside `1..65535`, including `"0"`) is a user error — it throws rather than
|
|
7
|
+
* silently falling back to the default, so a typo'd port fails loudly instead of
|
|
8
|
+
* binding the wrong one. Only an absent value falls through to the default.
|
|
9
|
+
*
|
|
10
|
+
* The `5174` default matches the SSR dev servers (`PORT || 5174`), so every SSR
|
|
11
|
+
* target — dev and preview, Bun and Node — lands on the same port by default.
|
|
12
|
+
*
|
|
13
|
+
* @param flag - The `--port`/`-p` value, if supplied.
|
|
14
|
+
* @param env - The `PORT` env var, if set.
|
|
15
|
+
* @param fallback - Port to use when neither is supplied (default `5174`).
|
|
16
|
+
* @returns The resolved port number.
|
|
17
|
+
* @throws If a supplied value is not an integer in `1..65535`.
|
|
18
|
+
*/
|
|
19
|
+
export function resolvePort(flag, env, fallback = 5174) {
|
|
20
|
+
const raw = flag ?? env;
|
|
21
|
+
if (raw == null || raw === "")
|
|
22
|
+
return fallback;
|
|
23
|
+
const parsed = Number(raw);
|
|
24
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 65535) {
|
|
25
|
+
throw new Error(`Invalid port "${raw}": expected an integer between 1 and 65535.`);
|
|
26
|
+
}
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=resolvePort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePort.js","sourceRoot":"","sources":["../../../../src/lib/server/resolvePort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CACzB,IAAwB,EACxB,GAAuB,EACvB,QAAQ,GAAG,IAAI;IAEf,MAAM,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC;IACxB,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,QAAQ,CAAC;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,KAAK,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,iBAAiB,GAAG,6CAA6C,CAClE,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|