@cedarjs/vite 6.0.0-canary.2685 → 6.0.0-canary.2686
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2686",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
"@babel/parser": "7.29.7",
|
|
64
64
|
"@babel/traverse": "7.29.7",
|
|
65
65
|
"@babel/types": "7.29.7",
|
|
66
|
-
"@cedarjs/api": "6.0.0-canary.
|
|
67
|
-
"@cedarjs/api-server": "6.0.0-canary.
|
|
68
|
-
"@cedarjs/babel-config": "6.0.0-canary.
|
|
69
|
-
"@cedarjs/context": "6.0.0-canary.
|
|
70
|
-
"@cedarjs/cookie-jar": "6.0.0-canary.
|
|
71
|
-
"@cedarjs/graphql-server": "6.0.0-canary.
|
|
72
|
-
"@cedarjs/internal": "6.0.0-canary.
|
|
73
|
-
"@cedarjs/project-config": "6.0.0-canary.
|
|
74
|
-
"@cedarjs/server-store": "6.0.0-canary.
|
|
75
|
-
"@cedarjs/testing": "6.0.0-canary.
|
|
66
|
+
"@cedarjs/api": "6.0.0-canary.2686",
|
|
67
|
+
"@cedarjs/api-server": "6.0.0-canary.2686",
|
|
68
|
+
"@cedarjs/babel-config": "6.0.0-canary.2686",
|
|
69
|
+
"@cedarjs/context": "6.0.0-canary.2686",
|
|
70
|
+
"@cedarjs/cookie-jar": "6.0.0-canary.2686",
|
|
71
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2686",
|
|
72
|
+
"@cedarjs/internal": "6.0.0-canary.2686",
|
|
73
|
+
"@cedarjs/project-config": "6.0.0-canary.2686",
|
|
74
|
+
"@cedarjs/server-store": "6.0.0-canary.2686",
|
|
75
|
+
"@cedarjs/testing": "6.0.0-canary.2686",
|
|
76
76
|
"@fastify/url-data": "6.0.3",
|
|
77
77
|
"@swc/core": "1.15.41",
|
|
78
78
|
"@universal-deploy/store": "^0.2.1",
|
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@arethetypeswrong/cli": "0.18.5",
|
|
112
|
-
"@cedarjs/auth": "6.0.0-canary.
|
|
113
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
114
|
-
"@cedarjs/web": "6.0.0-canary.
|
|
112
|
+
"@cedarjs/auth": "6.0.0-canary.2686",
|
|
113
|
+
"@cedarjs/router": "6.0.0-canary.2686",
|
|
114
|
+
"@cedarjs/web": "6.0.0-canary.2686",
|
|
115
115
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|
|
116
116
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
117
117
|
"@types/aws-lambda": "8.10.162",
|
package/dist/cjs/devFeServer.js
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
-
mod
|
|
24
|
-
));
|
|
25
|
-
var import_node_http = __toESM(require("node:http"), 1);
|
|
26
|
-
var import_server = require("@whatwg-node/server");
|
|
27
|
-
var import_express = __toESM(require("express"), 1);
|
|
28
|
-
var import_vite = require("vite");
|
|
29
|
-
var import_vite_plugin_cjs_interop = require("vite-plugin-cjs-interop");
|
|
30
|
-
var import_routes = require("@cedarjs/internal/dist/routes.js");
|
|
31
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
32
|
-
var import_server_store = require("@cedarjs/server-store");
|
|
33
|
-
var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.js");
|
|
34
|
-
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
35
|
-
var import_register = require("./middleware/register.js");
|
|
36
|
-
var import_vite_plugin_rsc_routes_auto_loader = require("./plugins/vite-plugin-rsc-routes-auto-loader.js");
|
|
37
|
-
var import_vite_plugin_rsc_routes_imports = require("./plugins/vite-plugin-rsc-routes-imports.js");
|
|
38
|
-
var import_vite_plugin_rsc_ssr_router_import = require("./plugins/vite-plugin-rsc-ssr-router-import.js");
|
|
39
|
-
var import_vite_plugin_rsc_transform_server = require("./plugins/vite-plugin-rsc-transform-server.js");
|
|
40
|
-
var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
|
|
41
|
-
var import_collectCss = require("./streaming/collectCss.js");
|
|
42
|
-
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
43
|
-
var import_utils = require("./utils.js");
|
|
44
|
-
const import_meta = {};
|
|
45
|
-
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
46
|
-
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
47
|
-
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
48
|
-
async function createServer() {
|
|
49
|
-
(0, import_utils.ensureProcessDirWeb)();
|
|
50
|
-
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
51
|
-
const app = (0, import_express.default)();
|
|
52
|
-
const server = import_node_http.default.createServer(app);
|
|
53
|
-
const rwPaths = (0, import_project_config.getPaths)();
|
|
54
|
-
const rscEnabled = (0, import_project_config.getConfig)().experimental.rsc?.enabled ?? false;
|
|
55
|
-
const serverStorage = (0, import_server_store.createServerStorage)();
|
|
56
|
-
app.use("*", (req, _res, next) => {
|
|
57
|
-
const fullUrl = (0, import_utils.getFullUrl)(req, rscEnabled);
|
|
58
|
-
const perReqStore = (0, import_server_store.createPerRequestMap)({
|
|
59
|
-
// Convert express headers to fetch header
|
|
60
|
-
headers: (0, import_utils.convertExpressHeaders)(req.headersDistinct),
|
|
61
|
-
fullUrl
|
|
62
|
-
});
|
|
63
|
-
serverStorage.run(perReqStore, next);
|
|
64
|
-
});
|
|
65
|
-
if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
"Vite entry points not found. Please check that your project has an entry.client.{jsx,tsx} and entry.server.{jsx,tsx} file in the web/src directory."
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
if (!rwPaths.web.viteConfig) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
"Vite config not found. Please set up Vite before running the dev server."
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const viteSsrDevServer = await (0, import_vite.createServer)({
|
|
76
|
-
configFile: rwPaths.web.viteConfig,
|
|
77
|
-
envFile: false,
|
|
78
|
-
define: {
|
|
79
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
80
|
-
},
|
|
81
|
-
ssr: {
|
|
82
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
83
|
-
// inline dependencies in the server build. This gets round runtime
|
|
84
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
85
|
-
//
|
|
86
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
87
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
88
|
-
// noExternal: true,
|
|
89
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
90
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
91
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
92
|
-
// we wanted to go that route.
|
|
93
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
94
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
95
|
-
// (css pre-init failure)
|
|
96
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
97
|
-
external: [
|
|
98
|
-
"@prisma/client",
|
|
99
|
-
"@prisma/adapter-better-sqlite3",
|
|
100
|
-
"@prisma/fetch-engine",
|
|
101
|
-
"@prisma/internals",
|
|
102
|
-
"better-sqlite3",
|
|
103
|
-
"@cedarjs/auth-dbauth-api",
|
|
104
|
-
"@cedarjs/cookie-jar",
|
|
105
|
-
"@cedarjs/server-store",
|
|
106
|
-
"@simplewebauthn/server",
|
|
107
|
-
"graphql-scalars",
|
|
108
|
-
"minimatch",
|
|
109
|
-
"playwright",
|
|
110
|
-
"react-dom"
|
|
111
|
-
],
|
|
112
|
-
resolve: {
|
|
113
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
114
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
115
|
-
// dependencies apart from node built-ins.
|
|
116
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
117
|
-
// `externalConditions`? When is one used over the other?
|
|
118
|
-
// conditions: ['react-server'],
|
|
119
|
-
// externalConditions: ['react-server'],
|
|
120
|
-
},
|
|
121
|
-
optimizeDeps: {
|
|
122
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
123
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
124
|
-
// include: [
|
|
125
|
-
// 'react/**/*',
|
|
126
|
-
// 'react-dom/server',
|
|
127
|
-
// 'react-dom/server.edge',
|
|
128
|
-
// 'rehackt',
|
|
129
|
-
// 'react-server-dom-webpack/server',
|
|
130
|
-
// 'react-server-dom-webpack/client',
|
|
131
|
-
// '@apollo/client/cache/*',
|
|
132
|
-
// '@apollo/client/utilities/*',
|
|
133
|
-
// '@apollo/client/react/hooks/*',
|
|
134
|
-
// 'react-fast-compare',
|
|
135
|
-
// 'invariant',
|
|
136
|
-
// 'shallowequal',
|
|
137
|
-
// 'graphql/language/*',
|
|
138
|
-
// 'stacktracey',
|
|
139
|
-
// 'deepmerge',
|
|
140
|
-
// 'fast-glob',
|
|
141
|
-
// ],
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
resolve: {
|
|
145
|
-
// conditions: ['react-server'],
|
|
146
|
-
},
|
|
147
|
-
plugins: [
|
|
148
|
-
(0, import_vite_plugin_cjs_interop.cjsInterop)({
|
|
149
|
-
dependencies: [
|
|
150
|
-
// Skip ESM modules: rwjs/auth, rwjs/web, rwjs/auth-*-middleware, rwjs/router
|
|
151
|
-
"@cedarjs/forms",
|
|
152
|
-
"@cedarjs/prerender/*",
|
|
153
|
-
"@cedarjs/auth-*-api",
|
|
154
|
-
// Add more to the pattern below as they're converted to dual ESM/CJS
|
|
155
|
-
// modules
|
|
156
|
-
// '@cedarjs/auth-!(dbauth|auth0|clerk)-web',
|
|
157
|
-
"@cedarjs/auth-!(dbauth)-web"
|
|
158
|
-
]
|
|
159
|
-
}),
|
|
160
|
-
rscEnabled && (0, import_vite_plugin_rsc_routes_auto_loader.rscRoutesAutoLoader)(),
|
|
161
|
-
rscEnabled && (0, import_vite_plugin_rsc_ssr_router_import.rscSsrRouterImport)()
|
|
162
|
-
],
|
|
163
|
-
server: { middlewareMode: true },
|
|
164
|
-
logLevel: "info",
|
|
165
|
-
clearScreen: false,
|
|
166
|
-
appType: "custom"
|
|
167
|
-
});
|
|
168
|
-
globalThis.__cedarjs__vite_ssr_runtime = (0, import_vite.createServerModuleRunner)(
|
|
169
|
-
viteSsrDevServer.environments.ssr
|
|
170
|
-
);
|
|
171
|
-
globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
|
|
172
|
-
globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
|
|
173
|
-
const viteRscServer = await (0, import_vite.createServer)({
|
|
174
|
-
envFile: false,
|
|
175
|
-
define: {
|
|
176
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
177
|
-
},
|
|
178
|
-
ssr: {
|
|
179
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
180
|
-
// inline dependencies in the server build. This gets round runtime
|
|
181
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
182
|
-
//
|
|
183
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
184
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
185
|
-
noExternal: true,
|
|
186
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
187
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
188
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
189
|
-
// we wanted to go that route.
|
|
190
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
191
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
192
|
-
// (css pre-init failure)
|
|
193
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
194
|
-
external: [
|
|
195
|
-
"@prisma/client",
|
|
196
|
-
"@prisma/adapter-better-sqlite3",
|
|
197
|
-
"@prisma/fetch-engine",
|
|
198
|
-
"@prisma/internals",
|
|
199
|
-
"better-sqlite3",
|
|
200
|
-
"@cedarjs/auth-dbauth-api",
|
|
201
|
-
"@cedarjs/cookie-jar",
|
|
202
|
-
"@cedarjs/server-store",
|
|
203
|
-
"@cedarjs/structure",
|
|
204
|
-
"@simplewebauthn/server",
|
|
205
|
-
"graphql-scalars",
|
|
206
|
-
"minimatch",
|
|
207
|
-
"playwright",
|
|
208
|
-
"react-dom"
|
|
209
|
-
],
|
|
210
|
-
resolve: {
|
|
211
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
212
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
213
|
-
// dependencies apart from node built-ins.
|
|
214
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
215
|
-
// `externalConditions`? When is one used over the other?
|
|
216
|
-
// In Vite 6, we must include `defaultServerConditions` alongside
|
|
217
|
-
// `react-server` so that nested condition maps (e.g. the `node`
|
|
218
|
-
// sub-condition inside `react-server-dom-webpack/server`'s exports)
|
|
219
|
-
// can still be resolved. Without `node` (or another environment
|
|
220
|
-
// condition), the resolver throws "No known conditions for
|
|
221
|
-
// './server' specifier in 'react-server-dom-webpack' package".
|
|
222
|
-
conditions: ["react-server", ...import_vite.defaultServerConditions],
|
|
223
|
-
externalConditions: ["react-server", ...import_vite.defaultServerConditions]
|
|
224
|
-
},
|
|
225
|
-
optimizeDeps: {
|
|
226
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
227
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
228
|
-
include: [
|
|
229
|
-
"react/**/*",
|
|
230
|
-
"react-dom/server",
|
|
231
|
-
"react-dom/server.edge",
|
|
232
|
-
"react-server-dom-webpack/server",
|
|
233
|
-
"react-server-dom-webpack/server.edge",
|
|
234
|
-
"react-server-dom-webpack/client",
|
|
235
|
-
"react-server-dom-webpack/client.edge",
|
|
236
|
-
"@apollo/client",
|
|
237
|
-
"@apollo/client/cache",
|
|
238
|
-
"@apollo/client/link/context",
|
|
239
|
-
"@apollo/client/link/persisted-queries",
|
|
240
|
-
"@apollo/client/react",
|
|
241
|
-
"@apollo/client/utilities",
|
|
242
|
-
"rxjs",
|
|
243
|
-
"react-fast-compare",
|
|
244
|
-
"invariant",
|
|
245
|
-
"shallowequal",
|
|
246
|
-
"graphql/language/*",
|
|
247
|
-
"stacktracey",
|
|
248
|
-
"deepmerge",
|
|
249
|
-
"fast-glob",
|
|
250
|
-
"@whatwg-node/fetch",
|
|
251
|
-
"busboy",
|
|
252
|
-
"cookie"
|
|
253
|
-
],
|
|
254
|
-
// Ensure `util` resolves to Node's built-in module and not to
|
|
255
|
-
// Browserify's `node-util` polyfill (which lacks TextEncoder).
|
|
256
|
-
// The polyfill may be hoisted into node_modules by optional
|
|
257
|
-
// dependencies like `@cedarjs/storybook`.
|
|
258
|
-
exclude: ["util"]
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
resolve: {
|
|
262
|
-
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
263
|
-
conditions: ["react-server", ...import_vite.defaultServerConditions]
|
|
264
|
-
},
|
|
265
|
-
plugins: [
|
|
266
|
-
{
|
|
267
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
268
|
-
transform(code, id, _options) {
|
|
269
|
-
globalThis.__cedarjs__client_references?.delete(id);
|
|
270
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
271
|
-
return void 0;
|
|
272
|
-
}
|
|
273
|
-
console.log(
|
|
274
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
275
|
-
id
|
|
276
|
-
);
|
|
277
|
-
globalThis.__cedarjs__client_references?.add(id);
|
|
278
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
279
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
280
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
281
|
-
const result = [
|
|
282
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
283
|
-
"",
|
|
284
|
-
...names.map((name) => {
|
|
285
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
286
|
-
})
|
|
287
|
-
].join("\n");
|
|
288
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
289
|
-
console.log(
|
|
290
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
291
|
-
);
|
|
292
|
-
return { code: result, map: null };
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
(0, import_vite_plugin_rsc_transform_server.rscTransformUseServerPlugin)("", {}),
|
|
296
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
297
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
298
|
-
// to
|
|
299
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
300
|
-
// That's why it needs the `clientEntryFiles` data
|
|
301
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
302
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
303
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
304
|
-
(0, import_vite_plugin_rsc_routes_imports.rscRoutesImports)(),
|
|
305
|
-
{
|
|
306
|
-
name: "rsc-hot-update",
|
|
307
|
-
handleHotUpdate(ctx) {
|
|
308
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
309
|
-
return [];
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
],
|
|
313
|
-
build: {
|
|
314
|
-
ssr: true
|
|
315
|
-
},
|
|
316
|
-
server: {
|
|
317
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
318
|
-
// middleware mode
|
|
319
|
-
middlewareMode: true,
|
|
320
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
321
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
322
|
-
// different port.
|
|
323
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
324
|
-
// port
|
|
325
|
-
ws: false
|
|
326
|
-
// hmr: {
|
|
327
|
-
// port: 24679,
|
|
328
|
-
// },
|
|
329
|
-
},
|
|
330
|
-
appType: "custom",
|
|
331
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
332
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
333
|
-
});
|
|
334
|
-
globalThis.__cedarjs__vite_rsc_runtime = (0, import_vite.createServerModuleRunner)(
|
|
335
|
-
viteRscServer.environments.ssr
|
|
336
|
-
);
|
|
337
|
-
const handleWithMiddleware = (route) => {
|
|
338
|
-
return (0, import_server.createServerAdapter)(async (req) => {
|
|
339
|
-
const middlewareRouter = await (0, import_register.createMiddlewareRouter)(viteSsrDevServer);
|
|
340
|
-
const middleware = middlewareRouter.find(
|
|
341
|
-
req.method,
|
|
342
|
-
req.url
|
|
343
|
-
)?.handler;
|
|
344
|
-
if (!middleware) {
|
|
345
|
-
return new Response("No middleware found", { status: 404 });
|
|
346
|
-
}
|
|
347
|
-
const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, middleware, {
|
|
348
|
-
route,
|
|
349
|
-
viteSsrDevServer
|
|
350
|
-
});
|
|
351
|
-
return mwRes.toResponse();
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
app.use(viteSsrDevServer.middlewares);
|
|
355
|
-
if (rscEnabled) {
|
|
356
|
-
(0, import_rscWebSocketServer.createWebSocketServer)();
|
|
357
|
-
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
358
|
-
new URL("./rsc/rscRequestHandler.js", import_meta.url).pathname
|
|
359
|
-
);
|
|
360
|
-
app.use(
|
|
361
|
-
"/rw-rsc",
|
|
362
|
-
await createRscRequestHandler({
|
|
363
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer),
|
|
364
|
-
viteSsrDevServer
|
|
365
|
-
})
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
const routes = (0, import_routes.getProjectRoutes)();
|
|
369
|
-
const routeHandler = await (0, import_createReactStreamingHandler.createReactStreamingHandler)(
|
|
370
|
-
{
|
|
371
|
-
routes,
|
|
372
|
-
clientEntryPath: rwPaths.web.entryClient,
|
|
373
|
-
getStylesheetLinks: (route) => {
|
|
374
|
-
return getCssLinks({
|
|
375
|
-
rwPaths,
|
|
376
|
-
route,
|
|
377
|
-
viteSsrDevServer
|
|
378
|
-
});
|
|
379
|
-
},
|
|
380
|
-
// Recreate middleware router on each request in dev
|
|
381
|
-
getMiddlewareRouter: async () => (0, import_register.createMiddlewareRouter)(viteSsrDevServer)
|
|
382
|
-
},
|
|
383
|
-
viteSsrDevServer
|
|
384
|
-
);
|
|
385
|
-
app.get("*", (0, import_server.createServerAdapter)(routeHandler));
|
|
386
|
-
app.post("*", handleWithMiddleware());
|
|
387
|
-
const port = (0, import_project_config.getConfig)().web.port;
|
|
388
|
-
console.log(`Started server on http://localhost:${port}`);
|
|
389
|
-
return server.listen(port);
|
|
390
|
-
}
|
|
391
|
-
let devApp = createServer();
|
|
392
|
-
process.stdin.on("data", async (data) => {
|
|
393
|
-
const str = data.toString().trim().toLowerCase();
|
|
394
|
-
if (str === "rs" || str === "restart") {
|
|
395
|
-
console.log("Restarting dev web server.....");
|
|
396
|
-
(await devApp).close(() => {
|
|
397
|
-
devApp = createServer();
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
function getCssLinks({
|
|
402
|
-
rwPaths,
|
|
403
|
-
route,
|
|
404
|
-
viteSsrDevServer
|
|
405
|
-
}) {
|
|
406
|
-
const appAndRouteModules = (0, import_collectCss.componentsModules)(
|
|
407
|
-
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
408
|
-
viteSsrDevServer
|
|
409
|
-
);
|
|
410
|
-
const collectedCss = (0, import_collectCss.collectCssPaths)(appAndRouteModules);
|
|
411
|
-
const cssLinks = Array.from(collectedCss);
|
|
412
|
-
return cssLinks;
|
|
413
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var registerFwGlobalsAndShims_exports = {};
|
|
20
|
-
__export(registerFwGlobalsAndShims_exports, {
|
|
21
|
-
registerFwGlobalsAndShims: () => registerFwGlobalsAndShims
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(registerFwGlobalsAndShims_exports);
|
|
24
|
-
var import_node_module = require("node:module");
|
|
25
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
26
|
-
const import_meta = {};
|
|
27
|
-
const registerFwGlobalsAndShims = () => {
|
|
28
|
-
registerFwGlobals();
|
|
29
|
-
registerFwShims();
|
|
30
|
-
};
|
|
31
|
-
function registerFwGlobals() {
|
|
32
|
-
const rwConfig = (0, import_project_config.getConfig)();
|
|
33
|
-
const envVars = (0, import_project_config.getEnvVarDefinitions)();
|
|
34
|
-
globalThis.RWJS_ENV = {
|
|
35
|
-
...envVars.RWJS_ENV,
|
|
36
|
-
RWJS_EXP_SSR_GRAPHQL_ENDPOINT: (() => {
|
|
37
|
-
const apiPath = rwConfig.web.apiGraphQLUrl ?? rwConfig.web.apiUrl + "/graphql";
|
|
38
|
-
if (/^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(apiPath)) {
|
|
39
|
-
return apiPath;
|
|
40
|
-
} else {
|
|
41
|
-
let webHost = process.env.REDWOOD_WEB_HOST;
|
|
42
|
-
webHost ??= rwConfig.web.host;
|
|
43
|
-
webHost ??= process.env.NODE_ENV === "production" ? "0.0.0.0" : "[::]";
|
|
44
|
-
let webPort;
|
|
45
|
-
if (process.env.REDWOOD_WEB_PORT) {
|
|
46
|
-
webPort = parseInt(process.env.REDWOOD_WEB_PORT);
|
|
47
|
-
} else {
|
|
48
|
-
webPort = rwConfig.web.port;
|
|
49
|
-
}
|
|
50
|
-
const proxiedApiUrl = swapLocalhostFor127(
|
|
51
|
-
"http://" + webHost + ":" + webPort + apiPath
|
|
52
|
-
);
|
|
53
|
-
if (process.env.NODE_ENV === "production" && !process.env.RWJS_EXP_SSR_GRAPHQL_ENDPOINT?.length) {
|
|
54
|
-
console.log("------------------ WARNING ! -------------------------");
|
|
55
|
-
console.warn();
|
|
56
|
-
console.warn();
|
|
57
|
-
console.warn(`You haven't configured your API absolute url.`);
|
|
58
|
-
console.warn(`Using ${proxiedApiUrl}`);
|
|
59
|
-
console.warn();
|
|
60
|
-
console.warn(
|
|
61
|
-
"You can override this for SSR by setting RWJS_EXP_SSR_GRAPHQL_ENDPOINT in your environment vars"
|
|
62
|
-
);
|
|
63
|
-
console.warn();
|
|
64
|
-
console.log("------------------ WARNING ! -------------------------");
|
|
65
|
-
return proxiedApiUrl;
|
|
66
|
-
}
|
|
67
|
-
return swapLocalhostFor127(
|
|
68
|
-
process.env.RWJS_EXP_SSR_GRAPHQL_ENDPOINT ?? proxiedApiUrl
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
})()
|
|
72
|
-
};
|
|
73
|
-
globalThis.RWJS_DEBUG_ENV = envVars.RWJS_DEBUG_ENV;
|
|
74
|
-
}
|
|
75
|
-
function registerFwShims() {
|
|
76
|
-
if (!(0, import_project_config.getConfig)().experimental?.rsc?.enabled) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
80
|
-
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
81
|
-
console.log("registerFwShims chunk load id", id);
|
|
82
|
-
if (globalThis.__cedarjs__vite_ssr_runtime) {
|
|
83
|
-
return globalThis.__cedarjs__vite_ssr_runtime?.import(id).then((mod) => {
|
|
84
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
85
|
-
if (mod.default && typeof mod.default === "object") {
|
|
86
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
87
|
-
}
|
|
88
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return import(id).then((mod) => {
|
|
92
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
93
|
-
if (mod.default && typeof mod.default === "object") {
|
|
94
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
95
|
-
}
|
|
96
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
globalThis.__webpack_require__ ||= (id) => {
|
|
100
|
-
console.log("registerFwShims require id", id);
|
|
101
|
-
return globalThis.__rw_module_cache__.get(id);
|
|
102
|
-
};
|
|
103
|
-
globalThis.__non_webpack_require__ ||= (0, import_node_module.createRequire)(import_meta.url);
|
|
104
|
-
}
|
|
105
|
-
function swapLocalhostFor127(hostString) {
|
|
106
|
-
return hostString.replace("localhost", "127.0.0.1");
|
|
107
|
-
}
|
|
108
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
-
0 && (module.exports = {
|
|
110
|
-
registerFwGlobalsAndShims
|
|
111
|
-
});
|
package/dist/cjs/runFeServer.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var runFeServer_exports = {};
|
|
31
|
-
__export(runFeServer_exports, {
|
|
32
|
-
runFeServer: () => runFeServer
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(runFeServer_exports);
|
|
35
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
-
var import_node_url = __toESM(require("node:url"), 1);
|
|
37
|
-
var import_server = require("@whatwg-node/server");
|
|
38
|
-
var import_dotenv_defaults = require("dotenv-defaults");
|
|
39
|
-
var import_express = __toESM(require("express"), 1);
|
|
40
|
-
var import_http_proxy_middleware = require("http-proxy-middleware");
|
|
41
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
42
|
-
var import_rscCss = require("@cedarjs/router/rscCss");
|
|
43
|
-
var import_server_store = require("@cedarjs/server-store");
|
|
44
|
-
var import_registerFwGlobalsAndShims = require("./lib/registerFwGlobalsAndShims.js");
|
|
45
|
-
var import_invokeMiddleware = require("./middleware/invokeMiddleware.js");
|
|
46
|
-
var import_register = require("./middleware/register.js");
|
|
47
|
-
var import_rscWebSocketServer = require("./rsc/rscWebSocketServer.js");
|
|
48
|
-
var import_createReactStreamingHandler = require("./streaming/createReactStreamingHandler.js");
|
|
49
|
-
var import_utils = require("./utils.js");
|
|
50
|
-
(0, import_dotenv_defaults.config)({
|
|
51
|
-
path: import_node_path.default.join((0, import_project_config.getPaths)().base, ".env"),
|
|
52
|
-
defaults: import_node_path.default.join((0, import_project_config.getPaths)().base, ".env.defaults"),
|
|
53
|
-
multiline: true
|
|
54
|
-
});
|
|
55
|
-
async function runFeServer() {
|
|
56
|
-
const app = (0, import_express.default)();
|
|
57
|
-
const rwPaths = (0, import_project_config.getPaths)();
|
|
58
|
-
const rwConfig = (0, import_project_config.getConfig)();
|
|
59
|
-
const rscEnabled = rwConfig.experimental?.rsc?.enabled;
|
|
60
|
-
(0, import_registerFwGlobalsAndShims.registerFwGlobalsAndShims)();
|
|
61
|
-
if (rscEnabled) {
|
|
62
|
-
const { setClientEntries } = await import("./rsc/rscRenderer.js");
|
|
63
|
-
(0, import_rscWebSocketServer.createWebSocketServer)();
|
|
64
|
-
try {
|
|
65
|
-
await setClientEntries();
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error("Failed to load client entries");
|
|
68
|
-
console.error(e);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const routeManifestUrl = import_node_url.default.pathToFileURL(rwPaths.web.routeManifest).href;
|
|
73
|
-
const routeManifest = (await import(routeManifestUrl, { with: { type: "json" } })).default;
|
|
74
|
-
const clientBuildManifestUrl = import_node_url.default.pathToFileURL(
|
|
75
|
-
import_node_path.default.join(rwPaths.web.distBrowser, "client-build-manifest.json")
|
|
76
|
-
).href;
|
|
77
|
-
const clientBuildManifest = (await import(clientBuildManifestUrl, { with: { type: "json" } })).default;
|
|
78
|
-
const clientEntry = rscEnabled ? clientBuildManifest["src/entry.client.tsx"] || clientBuildManifest["src/entry.client.jsx"] : Object.values(clientBuildManifest).find(
|
|
79
|
-
(manifestItem) => manifestItem.isEntry
|
|
80
|
-
);
|
|
81
|
-
if (!clientEntry) {
|
|
82
|
-
throw new Error("Could not find client entry in build manifest");
|
|
83
|
-
}
|
|
84
|
-
const middlewareRouter = await (0, import_register.createMiddlewareRouter)();
|
|
85
|
-
const serverStorage = (0, import_server_store.createServerStorage)();
|
|
86
|
-
const handleWithMiddleware = () => {
|
|
87
|
-
return (0, import_server.createServerAdapter)(async (req) => {
|
|
88
|
-
const matchedMw = middlewareRouter.find(req.method, req.url);
|
|
89
|
-
const handler = matchedMw?.handler;
|
|
90
|
-
if (!matchedMw) {
|
|
91
|
-
return new Response("No middleware found", { status: 404 });
|
|
92
|
-
}
|
|
93
|
-
const [mwRes] = await (0, import_invokeMiddleware.invoke)(req, handler, {
|
|
94
|
-
params: matchedMw?.params
|
|
95
|
-
});
|
|
96
|
-
return mwRes.toResponse();
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
app.use(
|
|
100
|
-
"/assets",
|
|
101
|
-
import_express.default.static(rwPaths.web.distBrowser + "/assets", { index: false })
|
|
102
|
-
);
|
|
103
|
-
app.use("*", (req, _res, next) => {
|
|
104
|
-
const fullUrl = (0, import_utils.getFullUrl)(req, rscEnabled);
|
|
105
|
-
const headers = (0, import_utils.convertExpressHeaders)(req.headersDistinct);
|
|
106
|
-
const perReqStore = (0, import_server_store.createPerRequestMap)({ headers, fullUrl });
|
|
107
|
-
serverStorage.run(perReqStore, next);
|
|
108
|
-
});
|
|
109
|
-
app.use(
|
|
110
|
-
rwConfig.web.apiUrl,
|
|
111
|
-
(0, import_http_proxy_middleware.createProxyMiddleware)({
|
|
112
|
-
changeOrigin: false,
|
|
113
|
-
// Using 127.0.0.1 to force ipv4. With `localhost` you don't really know
|
|
114
|
-
// if it's going to be ipv4 or ipv6
|
|
115
|
-
target: `http://127.0.0.1:${rwConfig.api.port}`
|
|
116
|
-
})
|
|
117
|
-
);
|
|
118
|
-
if (rscEnabled) {
|
|
119
|
-
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
120
|
-
app.use(
|
|
121
|
-
"/rw-rsc",
|
|
122
|
-
await createRscRequestHandler({
|
|
123
|
-
getMiddlewareRouter: async () => middlewareRouter
|
|
124
|
-
})
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
app.use(import_express.default.static(rwPaths.web.distBrowser, { index: false }));
|
|
128
|
-
const getStylesheetLinks = rscEnabled ? (0, import_rscCss.getRscStylesheetLinkGenerator)(clientEntry.css) : () => clientEntry.css || [];
|
|
129
|
-
const routeHandler = await (0, import_createReactStreamingHandler.createReactStreamingHandler)({
|
|
130
|
-
routes: Object.values(routeManifest),
|
|
131
|
-
clientEntryPath: clientEntry.file,
|
|
132
|
-
getStylesheetLinks,
|
|
133
|
-
getMiddlewareRouter: async () => middlewareRouter
|
|
134
|
-
});
|
|
135
|
-
app.get("*", (0, import_server.createServerAdapter)(routeHandler));
|
|
136
|
-
app.post("*", handleWithMiddleware());
|
|
137
|
-
app.listen(rwConfig.web.port);
|
|
138
|
-
console.log(
|
|
139
|
-
`Started production FE server on http://localhost:${rwConfig.web.port}`
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
runFeServer();
|
|
143
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
-
0 && (module.exports = {
|
|
145
|
-
runFeServer
|
|
146
|
-
});
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var createReactStreamingHandler_exports = {};
|
|
30
|
-
__export(createReactStreamingHandler_exports, {
|
|
31
|
-
createReactStreamingHandler: () => createReactStreamingHandler
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(createReactStreamingHandler_exports);
|
|
34
|
-
var import_path = __toESM(require("path"), 1);
|
|
35
|
-
var import_fetch = require("@whatwg-node/fetch");
|
|
36
|
-
var import_isbot = require("isbot");
|
|
37
|
-
var import_AuthProviderState = require("@cedarjs/auth/dist/AuthProvider/AuthProviderState.js");
|
|
38
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
39
|
-
var import_util = require("@cedarjs/router/util");
|
|
40
|
-
var import_middleware = require("@cedarjs/web/middleware");
|
|
41
|
-
var import_invokeMiddleware = require("../middleware/invokeMiddleware.js");
|
|
42
|
-
var import_utils = require("../utils.js");
|
|
43
|
-
var import_streamHelpers = require("./streamHelpers.js");
|
|
44
|
-
var import_triggerRouteHooks = require("./triggerRouteHooks.js");
|
|
45
|
-
const isbot = (0, import_isbot.createIsbotFromList)(
|
|
46
|
-
import_isbot.list.filter((record) => !record.includes("chrome-lighthouse"))
|
|
47
|
-
);
|
|
48
|
-
const createReactStreamingHandler = async ({
|
|
49
|
-
routes,
|
|
50
|
-
clientEntryPath,
|
|
51
|
-
getStylesheetLinks,
|
|
52
|
-
getMiddlewareRouter
|
|
53
|
-
}, viteSsrDevServer) => {
|
|
54
|
-
const rwPaths = (0, import_project_config.getPaths)();
|
|
55
|
-
const rwConfig = (0, import_project_config.getConfig)();
|
|
56
|
-
const isProd = !viteSsrDevServer;
|
|
57
|
-
const middlewareRouter = await getMiddlewareRouter();
|
|
58
|
-
let entryServerImport;
|
|
59
|
-
let fallbackDocumentImport;
|
|
60
|
-
const rscEnabled = rwConfig.experimental?.rsc?.enabled;
|
|
61
|
-
if (isProd) {
|
|
62
|
-
if (rscEnabled) {
|
|
63
|
-
entryServerImport = await import((0, import_utils.makeFilePath)((0, import_project_config.getBuiltServerEntryFile)()));
|
|
64
|
-
} else {
|
|
65
|
-
entryServerImport = await import((0, import_utils.makeFilePath)((0, import_project_config.getBuiltServerEntryFile)()));
|
|
66
|
-
}
|
|
67
|
-
fallbackDocumentImport = await import((0, import_utils.makeFilePath)((0, import_project_config.getBuiltDocumentFile)()));
|
|
68
|
-
}
|
|
69
|
-
return async (req) => {
|
|
70
|
-
let mwResponse = import_middleware.MiddlewareResponse.next();
|
|
71
|
-
let decodedAuthState = {
|
|
72
|
-
...import_AuthProviderState.middlewareDefaultAuthProviderState,
|
|
73
|
-
cookieHeader: req.headers.get("cookie"),
|
|
74
|
-
roles: []
|
|
75
|
-
};
|
|
76
|
-
let currentRoute;
|
|
77
|
-
let parsedParams = {};
|
|
78
|
-
const currentUrl = new URL(req.url);
|
|
79
|
-
for (const route of routes) {
|
|
80
|
-
const { match, ...rest } = (0, import_util.matchPath)(
|
|
81
|
-
route.pathDefinition,
|
|
82
|
-
currentUrl.pathname
|
|
83
|
-
);
|
|
84
|
-
if (match) {
|
|
85
|
-
currentRoute = route;
|
|
86
|
-
parsedParams = rest;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const cssLinks = getStylesheetLinks(currentRoute);
|
|
91
|
-
if (middlewareRouter) {
|
|
92
|
-
const matchedMw = middlewareRouter.find(req.method, req.url);
|
|
93
|
-
[mwResponse, decodedAuthState] = await (0, import_invokeMiddleware.invoke)(
|
|
94
|
-
req,
|
|
95
|
-
matchedMw?.handler,
|
|
96
|
-
{
|
|
97
|
-
route: currentRoute,
|
|
98
|
-
cssPaths: cssLinks,
|
|
99
|
-
params: matchedMw?.params,
|
|
100
|
-
viteSsrDevServer
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
if (mwResponse.isRedirect() || mwResponse.body) {
|
|
104
|
-
return mwResponse.toResponse();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (!currentRoute) {
|
|
108
|
-
throw new Error("404 handling not implemented");
|
|
109
|
-
}
|
|
110
|
-
if (currentRoute.redirect) {
|
|
111
|
-
return new import_fetch.Response(null, {
|
|
112
|
-
status: 302,
|
|
113
|
-
headers: {
|
|
114
|
-
Location: currentRoute.redirect.to
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (!isProd) {
|
|
119
|
-
entryServerImport = await (0, import_utils.ssrLoadEntryServer)(viteSsrDevServer);
|
|
120
|
-
fallbackDocumentImport = await viteSsrDevServer.ssrLoadModule(
|
|
121
|
-
rwPaths.web.document
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
const ServerEntry = entryServerImport.ServerEntry || entryServerImport.default;
|
|
125
|
-
const FallbackDocument = fallbackDocumentImport.Document || fallbackDocumentImport.default;
|
|
126
|
-
let metaTags = [];
|
|
127
|
-
let routeHookPath = currentRoute.routeHooks;
|
|
128
|
-
if (isProd) {
|
|
129
|
-
routeHookPath = currentRoute.routeHooks ? import_path.default.join(rwPaths.web.distRouteHooks, currentRoute.routeHooks) : null;
|
|
130
|
-
}
|
|
131
|
-
const routeHookOutput = await (0, import_triggerRouteHooks.loadAndRunRouteHooks)({
|
|
132
|
-
paths: [(0, import_project_config.getAppRouteHook)(isProd), routeHookPath],
|
|
133
|
-
reqMeta: {
|
|
134
|
-
req,
|
|
135
|
-
parsedParams
|
|
136
|
-
},
|
|
137
|
-
viteSsrDevServer
|
|
138
|
-
});
|
|
139
|
-
metaTags = routeHookOutput.meta;
|
|
140
|
-
const jsBundles = [
|
|
141
|
-
viteSsrDevServer ? clientEntryPath : "/" + clientEntryPath
|
|
142
|
-
];
|
|
143
|
-
if (currentRoute.bundle) {
|
|
144
|
-
jsBundles.push("/" + currentRoute.bundle);
|
|
145
|
-
}
|
|
146
|
-
const isSeoCrawler = isbot(req.headers.get("user-agent") || "");
|
|
147
|
-
const reactResponse = await (0, import_streamHelpers.reactRenderToStreamResponse)(
|
|
148
|
-
mwResponse,
|
|
149
|
-
{
|
|
150
|
-
ServerEntry,
|
|
151
|
-
FallbackDocument,
|
|
152
|
-
currentUrl,
|
|
153
|
-
metaTags,
|
|
154
|
-
cssLinks,
|
|
155
|
-
isProd,
|
|
156
|
-
jsBundles,
|
|
157
|
-
authState: decodedAuthState
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
waitForAllReady: isSeoCrawler,
|
|
161
|
-
onError: (err) => {
|
|
162
|
-
if (!isProd && viteSsrDevServer) {
|
|
163
|
-
viteSsrDevServer.ssrFixStacktrace(err);
|
|
164
|
-
}
|
|
165
|
-
console.error(err);
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
viteSsrDevServer
|
|
169
|
-
);
|
|
170
|
-
return reactResponse;
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
-
0 && (module.exports = {
|
|
175
|
-
createReactStreamingHandler
|
|
176
|
-
});
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var streamHelpers_exports = {};
|
|
30
|
-
__export(streamHelpers_exports, {
|
|
31
|
-
reactRenderToStreamResponse: () => reactRenderToStreamResponse
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(streamHelpers_exports);
|
|
34
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
36
|
-
var import_utils = require("../utils.js");
|
|
37
|
-
var import_bufferedTransform = require("./transforms/bufferedTransform.js");
|
|
38
|
-
var import_cancelTimeoutTransform = require("./transforms/cancelTimeoutTransform.js");
|
|
39
|
-
var import_serverInjectionTransform = require("./transforms/serverInjectionTransform.js");
|
|
40
|
-
const import_meta = {};
|
|
41
|
-
const rscWebpackShims = `globalThis.__rw_module_cache__ ||= new Map();
|
|
42
|
-
|
|
43
|
-
globalThis.__webpack_chunk_load__ ||= (id) => {
|
|
44
|
-
console.log('rscWebpackShims chunk load id', id)
|
|
45
|
-
return import(id).then((mod) => {
|
|
46
|
-
console.log('rscWebpackShims chunk load mod', mod)
|
|
47
|
-
|
|
48
|
-
// checking mod.default to better support CJS. If it's an object, it's
|
|
49
|
-
// likely a CJS module. Otherwise it's probably an ES module with a
|
|
50
|
-
// default export
|
|
51
|
-
if (mod.default && typeof mod.default === 'object') {
|
|
52
|
-
return globalThis.__rw_module_cache__.set(id, mod.default)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return globalThis.__rw_module_cache__.set(id, mod)
|
|
56
|
-
})
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
globalThis.__webpack_require__ ||= (id) => {
|
|
60
|
-
console.log('rscWebpackShims require id', id)
|
|
61
|
-
return globalThis.__rw_module_cache__.get(id)
|
|
62
|
-
};
|
|
63
|
-
`;
|
|
64
|
-
async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions, viteDevServer) {
|
|
65
|
-
const { waitForAllReady = false } = streamOptions;
|
|
66
|
-
const {
|
|
67
|
-
ServerEntry,
|
|
68
|
-
FallbackDocument,
|
|
69
|
-
currentUrl,
|
|
70
|
-
metaTags,
|
|
71
|
-
cssLinks,
|
|
72
|
-
isProd,
|
|
73
|
-
jsBundles = [],
|
|
74
|
-
authState
|
|
75
|
-
} = renderOptions;
|
|
76
|
-
if (!isProd) {
|
|
77
|
-
jsBundles.push(
|
|
78
|
-
new URL("../../inject/reactRefresh.js", import_meta.url).pathname
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const assetMap = JSON.stringify({
|
|
82
|
-
css: cssLinks,
|
|
83
|
-
meta: metaTags
|
|
84
|
-
});
|
|
85
|
-
const rscEnabled = (0, import_project_config.getConfig)().experimental?.rsc?.enabled;
|
|
86
|
-
const { createElement } = rscEnabled ? await importModule("__cedarjs__react", !!viteDevServer) : await import("react");
|
|
87
|
-
const {
|
|
88
|
-
createInjector,
|
|
89
|
-
ServerHtmlProvider,
|
|
90
|
-
ServerInjectedHtml
|
|
91
|
-
} = rscEnabled ? await importModule("__cedarjs__server_inject", !!viteDevServer) : await import("@cedarjs/web/serverInject");
|
|
92
|
-
const { renderToString } = rscEnabled ? await importModule("rd-server", !!viteDevServer) : await import("react-dom/server");
|
|
93
|
-
const { injectionState, injectToPage } = createInjector();
|
|
94
|
-
const bufferTransform = (0, import_bufferedTransform.createBufferedTransformStream)();
|
|
95
|
-
const serverInjectionTransform = (0, import_serverInjectionTransform.createServerInjectionTransform)({
|
|
96
|
-
injectionState,
|
|
97
|
-
createElement,
|
|
98
|
-
ServerInjectedHtml,
|
|
99
|
-
renderToString,
|
|
100
|
-
onlyOnFlush: waitForAllReady
|
|
101
|
-
});
|
|
102
|
-
const controller = new AbortController();
|
|
103
|
-
const timeoutHandle = setTimeout(() => {
|
|
104
|
-
controller.abort();
|
|
105
|
-
}, 1e4);
|
|
106
|
-
const timeoutTransform = (0, import_cancelTimeoutTransform.createTimeoutTransform)(timeoutHandle);
|
|
107
|
-
const { ServerAuthProvider } = rscEnabled ? await importModule("__cedarjs__server_auth_provider", !!viteDevServer) : await import("@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js");
|
|
108
|
-
const { LocationProvider } = rscEnabled ? await importModule("__cedarjs__location", !!viteDevServer) : await import("@cedarjs/router/location");
|
|
109
|
-
const renderRoot = (url) => {
|
|
110
|
-
return createElement(
|
|
111
|
-
ServerAuthProvider,
|
|
112
|
-
{
|
|
113
|
-
value: authState
|
|
114
|
-
},
|
|
115
|
-
createElement(
|
|
116
|
-
LocationProvider,
|
|
117
|
-
{
|
|
118
|
-
location: url
|
|
119
|
-
},
|
|
120
|
-
createElement(
|
|
121
|
-
ServerHtmlProvider,
|
|
122
|
-
{
|
|
123
|
-
value: injectToPage
|
|
124
|
-
},
|
|
125
|
-
createElement(ServerEntry, {
|
|
126
|
-
css: cssLinks,
|
|
127
|
-
meta: metaTags
|
|
128
|
-
})
|
|
129
|
-
)
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
const bootstrapOptions = {
|
|
134
|
-
bootstrapScriptContent: (
|
|
135
|
-
// Only insert assetMap if client side JS will be loaded
|
|
136
|
-
jsBundles.length > 0 ? `window.__REDWOOD__ASSET_MAP = ${assetMap}; ${rscWebpackShims}` : void 0
|
|
137
|
-
),
|
|
138
|
-
bootstrapModules: jsBundles
|
|
139
|
-
};
|
|
140
|
-
const { renderToReadableStream } = rscEnabled ? await importModule("rd-server", !!viteDevServer) : await import("react-dom/server.edge");
|
|
141
|
-
try {
|
|
142
|
-
let didErrorOutsideShell = false;
|
|
143
|
-
const renderToStreamOptions = {
|
|
144
|
-
...bootstrapOptions,
|
|
145
|
-
signal: controller.signal,
|
|
146
|
-
onError: (err) => {
|
|
147
|
-
didErrorOutsideShell = true;
|
|
148
|
-
console.error("\u{1F53B} Caught error outside shell");
|
|
149
|
-
streamOptions.onError?.(err);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const root = renderRoot(currentUrl);
|
|
153
|
-
const reactStream = await renderToReadableStream(root, renderToStreamOptions);
|
|
154
|
-
if (waitForAllReady) {
|
|
155
|
-
await reactStream.allReady;
|
|
156
|
-
}
|
|
157
|
-
const transformsToApply = [
|
|
158
|
-
!waitForAllReady && bufferTransform,
|
|
159
|
-
serverInjectionTransform,
|
|
160
|
-
!waitForAllReady && timeoutTransform
|
|
161
|
-
];
|
|
162
|
-
const outputStream = applyStreamTransforms(
|
|
163
|
-
reactStream,
|
|
164
|
-
transformsToApply
|
|
165
|
-
);
|
|
166
|
-
mwRes.status = didErrorOutsideShell ? 500 : 200;
|
|
167
|
-
mwRes.body = outputStream;
|
|
168
|
-
mwRes.headers.set("content-type", "text/html");
|
|
169
|
-
return mwRes.toResponse();
|
|
170
|
-
} catch (e) {
|
|
171
|
-
console.error("\u{1F53B} Failed to render shell");
|
|
172
|
-
streamOptions.onError?.(e);
|
|
173
|
-
const fallbackShell = await renderToReadableStream(
|
|
174
|
-
FallbackDocument({
|
|
175
|
-
children: null,
|
|
176
|
-
css: cssLinks,
|
|
177
|
-
meta: metaTags
|
|
178
|
-
}),
|
|
179
|
-
bootstrapOptions
|
|
180
|
-
);
|
|
181
|
-
mwRes.status = 500;
|
|
182
|
-
mwRes.body = fallbackShell;
|
|
183
|
-
mwRes.headers.set("content-type", "text/html");
|
|
184
|
-
return mwRes.toResponse();
|
|
185
|
-
} finally {
|
|
186
|
-
clearTimeout(timeoutHandle);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function applyStreamTransforms(reactStream, transformsToApply) {
|
|
190
|
-
let outputStream = reactStream;
|
|
191
|
-
for (const transform of transformsToApply) {
|
|
192
|
-
if (!transform) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
outputStream = outputStream.pipeThrough(transform);
|
|
196
|
-
}
|
|
197
|
-
return outputStream;
|
|
198
|
-
}
|
|
199
|
-
async function importModule(mod, isDev) {
|
|
200
|
-
if (isDev) {
|
|
201
|
-
if (mod === "rd-server") {
|
|
202
|
-
const loadedMod = await import("react-dom/server.edge");
|
|
203
|
-
return loadedMod.default;
|
|
204
|
-
} else if (mod === "__cedarjs__react") {
|
|
205
|
-
const loadedMod = await import("react");
|
|
206
|
-
return loadedMod.default;
|
|
207
|
-
} else if (mod === "__cedarjs__location") {
|
|
208
|
-
const loadedMod = await import("@cedarjs/router/location");
|
|
209
|
-
return loadedMod;
|
|
210
|
-
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
211
|
-
const loadedMod = await import("@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js");
|
|
212
|
-
return loadedMod;
|
|
213
|
-
} else if (mod === "__cedarjs__server_inject") {
|
|
214
|
-
const loadedMod = await import("@cedarjs/web/serverInject");
|
|
215
|
-
return loadedMod;
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
const distSsr = (0, import_project_config.getPaths)().web.distSsr;
|
|
219
|
-
const rdServerPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "rd-server.mjs"));
|
|
220
|
-
const reactPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "__cedarjs__react.mjs"));
|
|
221
|
-
const locationPath = (0, import_utils.makeFilePath)(
|
|
222
|
-
import_node_path.default.join(distSsr, "__cedarjs__location.mjs")
|
|
223
|
-
);
|
|
224
|
-
const serverAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
225
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_auth_provider.mjs")
|
|
226
|
-
);
|
|
227
|
-
const serverInjectPath = (0, import_utils.makeFilePath)(
|
|
228
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_inject.mjs")
|
|
229
|
-
);
|
|
230
|
-
if (mod === "rd-server") {
|
|
231
|
-
return (await import(rdServerPath)).default;
|
|
232
|
-
} else if (mod === "__cedarjs__react") {
|
|
233
|
-
return (await import(reactPath)).default;
|
|
234
|
-
} else if (mod === "__cedarjs__location") {
|
|
235
|
-
return await import(locationPath);
|
|
236
|
-
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
237
|
-
return await import(serverAuthProviderPath);
|
|
238
|
-
} else if (mod === "__cedarjs__server_inject") {
|
|
239
|
-
return await import(serverInjectPath);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
throw new Error("Unknown module " + mod);
|
|
243
|
-
}
|
|
244
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
245
|
-
0 && (module.exports = {
|
|
246
|
-
reactRenderToStreamResponse
|
|
247
|
-
});
|