@cedarjs/vite 4.0.0-canary.13869 → 4.0.0-canary.13871
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/dist/buildUDApiServer.d.ts +22 -0
- package/dist/buildUDApiServer.d.ts.map +1 -0
- package/dist/buildUDApiServer.js +59 -0
- package/dist/cjs/buildUDApiServer.js +93 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/plugins/vite-plugin-cedar-dev-dispatcher.js +223 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +63 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-dev-dispatcher.js +189 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts +6 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +39 -0
- package/package.json +17 -13
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface BuildUDApiServerOptions {
|
|
2
|
+
verbose?: boolean;
|
|
3
|
+
apiRootPath?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Builds the API server Universal Deploy Node entry using Vite.
|
|
7
|
+
*
|
|
8
|
+
* Runs a Vite server build that:
|
|
9
|
+
* 1. Installs `cedarUniversalDeployPlugin()` to register `virtual:cedar-api`
|
|
10
|
+
* and resolve `virtual:ud:catch-all` → Cedar's aggregate fetch dispatcher
|
|
11
|
+
* 2. Installs `node()` from `@universal-deploy/node/vite` to emit a
|
|
12
|
+
* self-contained Node server entry at `api/dist/ud/index.js`
|
|
13
|
+
*
|
|
14
|
+
* The emitted entry can be launched directly: node api/dist/ud/index.js
|
|
15
|
+
* That is what `cedar serve api` does.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: The Vite "ssr" build target used here is a server-side module build
|
|
18
|
+
* concern — it is NOT related to Cedar HTML SSR or RSC. "ssr" simply means
|
|
19
|
+
* Vite produces a Node-compatible bundle rather than a browser bundle.
|
|
20
|
+
*/
|
|
21
|
+
export declare const buildUDApiServer: ({ verbose, apiRootPath, }?: BuildUDApiServerOptions) => Promise<void>;
|
|
22
|
+
//# sourceMappingURL=buildUDApiServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildUDApiServer.d.ts","sourceRoot":"","sources":["../src/buildUDApiServer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,gBAAgB,GAAU,4BAGpC,uBAA4B,kBA+D9B,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
3
|
+
const buildUDApiServer = async ({
|
|
4
|
+
verbose = false,
|
|
5
|
+
apiRootPath
|
|
6
|
+
} = {}) => {
|
|
7
|
+
const { build } = await import("vite");
|
|
8
|
+
const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
9
|
+
const { node } = await import("@universal-deploy/node/vite");
|
|
10
|
+
const rwPaths = getPaths();
|
|
11
|
+
const outDir = path.join(rwPaths.api.dist, "ud");
|
|
12
|
+
await build({
|
|
13
|
+
// No configFile — we configure everything inline so this build is
|
|
14
|
+
// self-contained and does not require a vite.config.ts in api/.
|
|
15
|
+
configFile: false,
|
|
16
|
+
envFile: false,
|
|
17
|
+
logLevel: verbose ? "info" : "warn",
|
|
18
|
+
plugins: [
|
|
19
|
+
// Registers virtual:cedar-api with @universal-deploy/store and resolves
|
|
20
|
+
// virtual:ud:catch-all → virtual:cedar-api → Cedar's aggregate fetchable.
|
|
21
|
+
cedarUniversalDeployPlugin({ apiRootPath }),
|
|
22
|
+
// Emits a self-contained Node server entry (api/dist/ud/index.js) that
|
|
23
|
+
// imports virtual:ud:catch-all and starts an srvx HTTP server.
|
|
24
|
+
// This is a Vite server-build concern, not Cedar HTML SSR.
|
|
25
|
+
...node()
|
|
26
|
+
],
|
|
27
|
+
// The ssr environment is the Vite mechanism for server-side builds.
|
|
28
|
+
// Reminder: "ssr" here means "server-side module execution", NOT
|
|
29
|
+
// Cedar HTML SSR / streaming / RSC.
|
|
30
|
+
environments: {
|
|
31
|
+
ssr: {
|
|
32
|
+
build: {
|
|
33
|
+
outDir,
|
|
34
|
+
// Ensure @universal-deploy/node is bundled into the output so the
|
|
35
|
+
// emitted entry is self-contained.
|
|
36
|
+
rollupOptions: {
|
|
37
|
+
output: {
|
|
38
|
+
// Produce a single-file entry where possible; srvx chunks are
|
|
39
|
+
// split by the node() plugin automatically.
|
|
40
|
+
entryFileNames: "[name].js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
resolve: {
|
|
45
|
+
// Do not externalise @universal-deploy/node — the node() plugin
|
|
46
|
+
// requires it to be bundled into the server entry.
|
|
47
|
+
noExternal: ["@universal-deploy/node"]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
build: {
|
|
52
|
+
// This is a server (Node) build, not a browser build.
|
|
53
|
+
ssr: true
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
buildUDApiServer
|
|
59
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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 buildUDApiServer_exports = {};
|
|
30
|
+
__export(buildUDApiServer_exports, {
|
|
31
|
+
buildUDApiServer: () => buildUDApiServer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(buildUDApiServer_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
36
|
+
const buildUDApiServer = async ({
|
|
37
|
+
verbose = false,
|
|
38
|
+
apiRootPath
|
|
39
|
+
} = {}) => {
|
|
40
|
+
const { build } = await import("vite");
|
|
41
|
+
const { cedarUniversalDeployPlugin } = await import("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
42
|
+
const { node } = await import("@universal-deploy/node/vite");
|
|
43
|
+
const rwPaths = (0, import_project_config.getPaths)();
|
|
44
|
+
const outDir = import_node_path.default.join(rwPaths.api.dist, "ud");
|
|
45
|
+
await build({
|
|
46
|
+
// No configFile — we configure everything inline so this build is
|
|
47
|
+
// self-contained and does not require a vite.config.ts in api/.
|
|
48
|
+
configFile: false,
|
|
49
|
+
envFile: false,
|
|
50
|
+
logLevel: verbose ? "info" : "warn",
|
|
51
|
+
plugins: [
|
|
52
|
+
// Registers virtual:cedar-api with @universal-deploy/store and resolves
|
|
53
|
+
// virtual:ud:catch-all → virtual:cedar-api → Cedar's aggregate fetchable.
|
|
54
|
+
cedarUniversalDeployPlugin({ apiRootPath }),
|
|
55
|
+
// Emits a self-contained Node server entry (api/dist/ud/index.js) that
|
|
56
|
+
// imports virtual:ud:catch-all and starts an srvx HTTP server.
|
|
57
|
+
// This is a Vite server-build concern, not Cedar HTML SSR.
|
|
58
|
+
...node()
|
|
59
|
+
],
|
|
60
|
+
// The ssr environment is the Vite mechanism for server-side builds.
|
|
61
|
+
// Reminder: "ssr" here means "server-side module execution", NOT
|
|
62
|
+
// Cedar HTML SSR / streaming / RSC.
|
|
63
|
+
environments: {
|
|
64
|
+
ssr: {
|
|
65
|
+
build: {
|
|
66
|
+
outDir,
|
|
67
|
+
// Ensure @universal-deploy/node is bundled into the output so the
|
|
68
|
+
// emitted entry is self-contained.
|
|
69
|
+
rollupOptions: {
|
|
70
|
+
output: {
|
|
71
|
+
// Produce a single-file entry where possible; srvx chunks are
|
|
72
|
+
// split by the node() plugin automatically.
|
|
73
|
+
entryFileNames: "[name].js"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
resolve: {
|
|
78
|
+
// Do not externalise @universal-deploy/node — the node() plugin
|
|
79
|
+
// requires it to be bundled into the server entry.
|
|
80
|
+
noExternal: ["@universal-deploy/node"]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
build: {
|
|
85
|
+
// This is a server (Node) build, not a browser build.
|
|
86
|
+
ssr: true
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
buildUDApiServer
|
|
93
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
cedar: () => cedar,
|
|
32
32
|
cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
|
|
33
33
|
cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
|
|
34
|
+
cedarDevDispatcherPlugin: () => import_vite_plugin_cedar_dev_dispatcher.cedarDevDispatcherPlugin,
|
|
34
35
|
cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
|
|
35
36
|
cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
|
|
36
37
|
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
@@ -39,6 +40,8 @@ __export(index_exports, {
|
|
|
39
40
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
40
41
|
cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
|
|
41
42
|
cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
|
|
43
|
+
cedarUniversalDeployPlugin: () => import_vite_plugin_cedar_universal_deploy.cedarUniversalDeployPlugin,
|
|
44
|
+
cedarWaitForApiServer: () => import_vite_plugin_cedar_wait_for_api_server2.cedarWaitForApiServer,
|
|
42
45
|
cedarjsJobPathInjectorPlugin: () => import_vite_plugin_cedarjs_job_path_injector.cedarjsJobPathInjectorPlugin,
|
|
43
46
|
cedarjsResolveCedarStyleImportsPlugin: () => import_vite_plugin_cedarjs_resolve_cedar_style_imports2.cedarjsResolveCedarStyleImportsPlugin,
|
|
44
47
|
default: () => index_default
|
|
@@ -70,6 +73,9 @@ var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugi
|
|
|
70
73
|
var import_vite_plugin_jsx_loader2 = require("./plugins/vite-plugin-jsx-loader.js");
|
|
71
74
|
var import_vite_plugin_merged_config2 = require("./plugins/vite-plugin-merged-config.js");
|
|
72
75
|
var import_vite_plugin_swap_apollo_provider2 = require("./plugins/vite-plugin-swap-apollo-provider.js");
|
|
76
|
+
var import_vite_plugin_cedar_universal_deploy = require("./plugins/vite-plugin-cedar-universal-deploy.js");
|
|
77
|
+
var import_vite_plugin_cedar_dev_dispatcher = require("./plugins/vite-plugin-cedar-dev-dispatcher.js");
|
|
78
|
+
var import_vite_plugin_cedar_wait_for_api_server2 = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
|
|
73
79
|
function cedar({ mode } = {}) {
|
|
74
80
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
75
81
|
const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
|
|
@@ -109,6 +115,7 @@ var index_default = cedar;
|
|
|
109
115
|
cedar,
|
|
110
116
|
cedarAutoImportsPlugin,
|
|
111
117
|
cedarCellTransform,
|
|
118
|
+
cedarDevDispatcherPlugin,
|
|
112
119
|
cedarEntryInjectionPlugin,
|
|
113
120
|
cedarHtmlEnvPlugin,
|
|
114
121
|
cedarImportDirPlugin,
|
|
@@ -117,6 +124,8 @@ var index_default = cedar;
|
|
|
117
124
|
cedarRemoveFromBundle,
|
|
118
125
|
cedarSwapApolloProvider,
|
|
119
126
|
cedarTransformJsAsJsx,
|
|
127
|
+
cedarUniversalDeployPlugin,
|
|
128
|
+
cedarWaitForApiServer,
|
|
120
129
|
cedarjsJobPathInjectorPlugin,
|
|
121
130
|
cedarjsResolveCedarStyleImportsPlugin
|
|
122
131
|
});
|
|
@@ -0,0 +1,223 @@
|
|
|
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 vite_plugin_cedar_dev_dispatcher_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_dev_dispatcher_exports, {
|
|
31
|
+
cedarDevDispatcherPlugin: () => cedarDevDispatcherPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_dev_dispatcher_exports);
|
|
34
|
+
var import_node_net = __toESM(require("node:net"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
let cachedDispatcher = null;
|
|
38
|
+
let dispatcherGeneration = 0;
|
|
39
|
+
let buildPromise = null;
|
|
40
|
+
async function getDispatcher() {
|
|
41
|
+
if (cachedDispatcher !== null) {
|
|
42
|
+
return cachedDispatcher;
|
|
43
|
+
}
|
|
44
|
+
if (buildPromise !== null) {
|
|
45
|
+
await buildPromise;
|
|
46
|
+
return cachedDispatcher ?? getDispatcher();
|
|
47
|
+
}
|
|
48
|
+
const generationAtStart = dispatcherGeneration;
|
|
49
|
+
buildPromise = (async () => {
|
|
50
|
+
try {
|
|
51
|
+
const { rebuildApi, buildApi } = await import("@cedarjs/internal/dist/build/api");
|
|
52
|
+
try {
|
|
53
|
+
await rebuildApi();
|
|
54
|
+
} catch {
|
|
55
|
+
await buildApi();
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.warn(
|
|
59
|
+
"[cedar-dev-dispatcher] API compilation failed; serving with last-known-good dist:",
|
|
60
|
+
err
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const { buildCedarDispatcher } = await import("@cedarjs/api-server/udDispatcher");
|
|
64
|
+
const { fetchable } = await buildCedarDispatcher({ cacheBust: Date.now() });
|
|
65
|
+
if (generationAtStart === dispatcherGeneration) {
|
|
66
|
+
cachedDispatcher = fetchable;
|
|
67
|
+
}
|
|
68
|
+
return fetchable;
|
|
69
|
+
})();
|
|
70
|
+
try {
|
|
71
|
+
await buildPromise;
|
|
72
|
+
} finally {
|
|
73
|
+
if (generationAtStart === dispatcherGeneration) {
|
|
74
|
+
buildPromise = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (cachedDispatcher !== null) {
|
|
78
|
+
return cachedDispatcher;
|
|
79
|
+
}
|
|
80
|
+
return getDispatcher();
|
|
81
|
+
}
|
|
82
|
+
function invalidateDispatcher() {
|
|
83
|
+
cachedDispatcher = null;
|
|
84
|
+
buildPromise = null;
|
|
85
|
+
dispatcherGeneration++;
|
|
86
|
+
}
|
|
87
|
+
function isViteInternalRequest(url) {
|
|
88
|
+
return url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/__hmr") || url.includes("?import") || url.includes("?t=") || url.includes("?v=");
|
|
89
|
+
}
|
|
90
|
+
async function nodeRequestToFetch(req) {
|
|
91
|
+
const host = req.headers.host ?? "localhost";
|
|
92
|
+
const url = `http://${host}${req.url ?? "/"}`;
|
|
93
|
+
const headers = new Headers();
|
|
94
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
95
|
+
if (value === void 0) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
for (const v of value) {
|
|
100
|
+
headers.append(key, v);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
headers.set(key, value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
107
|
+
const hasBody = ["POST", "PUT", "PATCH", "DELETE"].includes(method);
|
|
108
|
+
let body;
|
|
109
|
+
if (hasBody) {
|
|
110
|
+
body = await new Promise((resolve, reject) => {
|
|
111
|
+
const chunks = [];
|
|
112
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
113
|
+
req.on("end", () => resolve(Buffer.concat(chunks)));
|
|
114
|
+
req.on("error", reject);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return new Request(url, {
|
|
118
|
+
method,
|
|
119
|
+
headers,
|
|
120
|
+
body: hasBody && body && body.length > 0 ? new Uint8Array(body) : void 0
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async function fetchResponseToNode(fetchRes, res) {
|
|
124
|
+
res.statusCode = fetchRes.status;
|
|
125
|
+
fetchRes.headers.forEach((value, key) => {
|
|
126
|
+
res.setHeader(key, value);
|
|
127
|
+
});
|
|
128
|
+
const bodyBuffer = await fetchRes.arrayBuffer();
|
|
129
|
+
if (bodyBuffer.byteLength > 0) {
|
|
130
|
+
res.end(Buffer.from(bodyBuffer));
|
|
131
|
+
} else {
|
|
132
|
+
res.end();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let apiServerIsUp;
|
|
136
|
+
async function checkApiPort(host, port) {
|
|
137
|
+
return new Promise((resolve) => {
|
|
138
|
+
const socket = new import_node_net.default.Socket();
|
|
139
|
+
socket.setTimeout(100);
|
|
140
|
+
socket.on("connect", () => {
|
|
141
|
+
socket.destroy();
|
|
142
|
+
resolve(true);
|
|
143
|
+
});
|
|
144
|
+
socket.on("timeout", () => {
|
|
145
|
+
socket.destroy();
|
|
146
|
+
resolve(false);
|
|
147
|
+
});
|
|
148
|
+
socket.on("error", () => {
|
|
149
|
+
socket.destroy();
|
|
150
|
+
resolve(false);
|
|
151
|
+
});
|
|
152
|
+
socket.connect(port, host);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function cedarDevDispatcherPlugin() {
|
|
156
|
+
return {
|
|
157
|
+
name: "cedar-dev-dispatcher",
|
|
158
|
+
apply: "serve",
|
|
159
|
+
configureServer(server) {
|
|
160
|
+
const cedarConfig = (0, import_project_config.getConfig)();
|
|
161
|
+
const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
|
|
162
|
+
const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
|
|
163
|
+
const apiPort = cedarConfig.api.port;
|
|
164
|
+
const apiHost = cedarConfig.api.host || "127.0.0.1";
|
|
165
|
+
function isApiRequest(url) {
|
|
166
|
+
return url === apiUrl || url.startsWith(apiUrl + "/") || url.startsWith(apiUrl + "?") || url === apiGqlUrl || url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?");
|
|
167
|
+
}
|
|
168
|
+
server.watcher.on("change", (filePath) => {
|
|
169
|
+
if (filePath.startsWith((0, import_project_config.getPaths)().api.src + import_node_path.default.sep)) {
|
|
170
|
+
invalidateDispatcher();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
server.middlewares.use(
|
|
174
|
+
async (req, res, next) => {
|
|
175
|
+
const url = req.url ?? "/";
|
|
176
|
+
if (isViteInternalRequest(url)) {
|
|
177
|
+
return next();
|
|
178
|
+
}
|
|
179
|
+
if (!isApiRequest(url)) {
|
|
180
|
+
return next();
|
|
181
|
+
}
|
|
182
|
+
if (apiServerIsUp === void 0) {
|
|
183
|
+
apiServerIsUp = await checkApiPort(apiHost, apiPort);
|
|
184
|
+
}
|
|
185
|
+
if (apiServerIsUp) {
|
|
186
|
+
return next();
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const dispatcher = await getDispatcher();
|
|
190
|
+
const fetchRequest = await nodeRequestToFetch(req);
|
|
191
|
+
const fetchResponse = await dispatcher.fetch(fetchRequest);
|
|
192
|
+
await fetchResponseToNode(fetchResponse, res);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.error(
|
|
195
|
+
"[cedar-dev-dispatcher] Error handling API request:",
|
|
196
|
+
err
|
|
197
|
+
);
|
|
198
|
+
if (!res.headersSent) {
|
|
199
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
200
|
+
}
|
|
201
|
+
res.end(
|
|
202
|
+
JSON.stringify(
|
|
203
|
+
{
|
|
204
|
+
errors: [
|
|
205
|
+
{
|
|
206
|
+
message: err instanceof Error ? err.message : "Internal Server Error"
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
null,
|
|
211
|
+
2
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
222
|
+
cedarDevDispatcherPlugin
|
|
223
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
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 vite_plugin_cedar_universal_deploy_exports = {};
|
|
20
|
+
__export(vite_plugin_cedar_universal_deploy_exports, {
|
|
21
|
+
cedarUniversalDeployPlugin: () => cedarUniversalDeployPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(vite_plugin_cedar_universal_deploy_exports);
|
|
24
|
+
var import_store = require("@universal-deploy/store");
|
|
25
|
+
const VIRTUAL_CEDAR_API = "virtual:cedar-api";
|
|
26
|
+
const RESOLVED_VIRTUAL_CEDAR_API = "\0virtual:cedar-api";
|
|
27
|
+
function cedarUniversalDeployPlugin(options = {}) {
|
|
28
|
+
const { apiRootPath } = options;
|
|
29
|
+
return {
|
|
30
|
+
name: "cedar-universal-deploy",
|
|
31
|
+
apply: "build",
|
|
32
|
+
buildStart() {
|
|
33
|
+
(0, import_store.addEntry)({
|
|
34
|
+
id: VIRTUAL_CEDAR_API,
|
|
35
|
+
route: "/**"
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
resolveId(id) {
|
|
39
|
+
if (id === import_store.catchAllEntry) {
|
|
40
|
+
return RESOLVED_VIRTUAL_CEDAR_API;
|
|
41
|
+
}
|
|
42
|
+
if (id === VIRTUAL_CEDAR_API) {
|
|
43
|
+
return RESOLVED_VIRTUAL_CEDAR_API;
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
},
|
|
47
|
+
load(id) {
|
|
48
|
+
if (id !== RESOLVED_VIRTUAL_CEDAR_API) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const apiRootPathArg = apiRootPath !== void 0 ? `{ apiRootPath: ${JSON.stringify(apiRootPath)} }` : "undefined";
|
|
52
|
+
return `
|
|
53
|
+
import { buildCedarDispatcher } from '@cedarjs/api-server/udDispatcher';
|
|
54
|
+
const { fetchable } = await buildCedarDispatcher(${apiRootPathArg});
|
|
55
|
+
export default fetchable;
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
cedarUniversalDeployPlugin
|
|
63
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export { cedarjsJobPathInjectorPlugin } from './plugins/vite-plugin-cedarjs-job-
|
|
|
11
11
|
export { cedarTransformJsAsJsx } from './plugins/vite-plugin-jsx-loader.js';
|
|
12
12
|
export { cedarMergedConfig } from './plugins/vite-plugin-merged-config.js';
|
|
13
13
|
export { cedarSwapApolloProvider } from './plugins/vite-plugin-swap-apollo-provider.js';
|
|
14
|
+
export { cedarUniversalDeployPlugin } from './plugins/vite-plugin-cedar-universal-deploy.js';
|
|
15
|
+
export { cedarDevDispatcherPlugin } from './plugins/vite-plugin-cedar-dev-dispatcher.js';
|
|
16
|
+
export { cedarWaitForApiServer } from './plugins/vite-plugin-cedar-wait-for-api-server.js';
|
|
14
17
|
type PluginOptions = {
|
|
15
18
|
mode?: string | undefined;
|
|
16
19
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAqBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAA;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAyClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,9 @@ import { cedarjsJobPathInjectorPlugin } from "./plugins/vite-plugin-cedarjs-job-
|
|
|
28
28
|
import { cedarTransformJsAsJsx as cedarTransformJsAsJsx2 } from "./plugins/vite-plugin-jsx-loader.js";
|
|
29
29
|
import { cedarMergedConfig as cedarMergedConfig2 } from "./plugins/vite-plugin-merged-config.js";
|
|
30
30
|
import { cedarSwapApolloProvider as cedarSwapApolloProvider2 } from "./plugins/vite-plugin-swap-apollo-provider.js";
|
|
31
|
+
import { cedarUniversalDeployPlugin } from "./plugins/vite-plugin-cedar-universal-deploy.js";
|
|
32
|
+
import { cedarDevDispatcherPlugin } from "./plugins/vite-plugin-cedar-dev-dispatcher.js";
|
|
33
|
+
import { cedarWaitForApiServer as cedarWaitForApiServer2 } from "./plugins/vite-plugin-cedar-wait-for-api-server.js";
|
|
31
34
|
function cedar({ mode } = {}) {
|
|
32
35
|
const cedarConfig = getConfig();
|
|
33
36
|
const rscEnabled = cedarConfig.experimental?.rsc?.enabled;
|
|
@@ -66,6 +69,7 @@ export {
|
|
|
66
69
|
cedar,
|
|
67
70
|
cedarAutoImportsPlugin,
|
|
68
71
|
cedarCellTransform2 as cedarCellTransform,
|
|
72
|
+
cedarDevDispatcherPlugin,
|
|
69
73
|
cedarEntryInjectionPlugin2 as cedarEntryInjectionPlugin,
|
|
70
74
|
cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
|
|
71
75
|
cedarImportDirPlugin,
|
|
@@ -74,6 +78,8 @@ export {
|
|
|
74
78
|
cedarRemoveFromBundle2 as cedarRemoveFromBundle,
|
|
75
79
|
cedarSwapApolloProvider2 as cedarSwapApolloProvider,
|
|
76
80
|
cedarTransformJsAsJsx2 as cedarTransformJsAsJsx,
|
|
81
|
+
cedarUniversalDeployPlugin,
|
|
82
|
+
cedarWaitForApiServer2 as cedarWaitForApiServer,
|
|
77
83
|
cedarjsJobPathInjectorPlugin,
|
|
78
84
|
cedarjsResolveCedarStyleImportsPlugin2 as cedarjsResolveCedarStyleImportsPlugin,
|
|
79
85
|
index_default as default
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-dev-dispatcher.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-dev-dispatcher.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AA+LjD,wBAAgB,wBAAwB,IAAI,MAAM,CA4FjD"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
4
|
+
let cachedDispatcher = null;
|
|
5
|
+
let dispatcherGeneration = 0;
|
|
6
|
+
let buildPromise = null;
|
|
7
|
+
async function getDispatcher() {
|
|
8
|
+
if (cachedDispatcher !== null) {
|
|
9
|
+
return cachedDispatcher;
|
|
10
|
+
}
|
|
11
|
+
if (buildPromise !== null) {
|
|
12
|
+
await buildPromise;
|
|
13
|
+
return cachedDispatcher ?? getDispatcher();
|
|
14
|
+
}
|
|
15
|
+
const generationAtStart = dispatcherGeneration;
|
|
16
|
+
buildPromise = (async () => {
|
|
17
|
+
try {
|
|
18
|
+
const { rebuildApi, buildApi } = await import("@cedarjs/internal/dist/build/api");
|
|
19
|
+
try {
|
|
20
|
+
await rebuildApi();
|
|
21
|
+
} catch {
|
|
22
|
+
await buildApi();
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.warn(
|
|
26
|
+
"[cedar-dev-dispatcher] API compilation failed; serving with last-known-good dist:",
|
|
27
|
+
err
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const { buildCedarDispatcher } = await import("@cedarjs/api-server/udDispatcher");
|
|
31
|
+
const { fetchable } = await buildCedarDispatcher({ cacheBust: Date.now() });
|
|
32
|
+
if (generationAtStart === dispatcherGeneration) {
|
|
33
|
+
cachedDispatcher = fetchable;
|
|
34
|
+
}
|
|
35
|
+
return fetchable;
|
|
36
|
+
})();
|
|
37
|
+
try {
|
|
38
|
+
await buildPromise;
|
|
39
|
+
} finally {
|
|
40
|
+
if (generationAtStart === dispatcherGeneration) {
|
|
41
|
+
buildPromise = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (cachedDispatcher !== null) {
|
|
45
|
+
return cachedDispatcher;
|
|
46
|
+
}
|
|
47
|
+
return getDispatcher();
|
|
48
|
+
}
|
|
49
|
+
function invalidateDispatcher() {
|
|
50
|
+
cachedDispatcher = null;
|
|
51
|
+
buildPromise = null;
|
|
52
|
+
dispatcherGeneration++;
|
|
53
|
+
}
|
|
54
|
+
function isViteInternalRequest(url) {
|
|
55
|
+
return url.startsWith("/@") || url.startsWith("/__vite") || url.startsWith("/__hmr") || url.includes("?import") || url.includes("?t=") || url.includes("?v=");
|
|
56
|
+
}
|
|
57
|
+
async function nodeRequestToFetch(req) {
|
|
58
|
+
const host = req.headers.host ?? "localhost";
|
|
59
|
+
const url = `http://${host}${req.url ?? "/"}`;
|
|
60
|
+
const headers = new Headers();
|
|
61
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
62
|
+
if (value === void 0) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
for (const v of value) {
|
|
67
|
+
headers.append(key, v);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
headers.set(key, value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
74
|
+
const hasBody = ["POST", "PUT", "PATCH", "DELETE"].includes(method);
|
|
75
|
+
let body;
|
|
76
|
+
if (hasBody) {
|
|
77
|
+
body = await new Promise((resolve, reject) => {
|
|
78
|
+
const chunks = [];
|
|
79
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
80
|
+
req.on("end", () => resolve(Buffer.concat(chunks)));
|
|
81
|
+
req.on("error", reject);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return new Request(url, {
|
|
85
|
+
method,
|
|
86
|
+
headers,
|
|
87
|
+
body: hasBody && body && body.length > 0 ? new Uint8Array(body) : void 0
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async function fetchResponseToNode(fetchRes, res) {
|
|
91
|
+
res.statusCode = fetchRes.status;
|
|
92
|
+
fetchRes.headers.forEach((value, key) => {
|
|
93
|
+
res.setHeader(key, value);
|
|
94
|
+
});
|
|
95
|
+
const bodyBuffer = await fetchRes.arrayBuffer();
|
|
96
|
+
if (bodyBuffer.byteLength > 0) {
|
|
97
|
+
res.end(Buffer.from(bodyBuffer));
|
|
98
|
+
} else {
|
|
99
|
+
res.end();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let apiServerIsUp;
|
|
103
|
+
async function checkApiPort(host, port) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
const socket = new net.Socket();
|
|
106
|
+
socket.setTimeout(100);
|
|
107
|
+
socket.on("connect", () => {
|
|
108
|
+
socket.destroy();
|
|
109
|
+
resolve(true);
|
|
110
|
+
});
|
|
111
|
+
socket.on("timeout", () => {
|
|
112
|
+
socket.destroy();
|
|
113
|
+
resolve(false);
|
|
114
|
+
});
|
|
115
|
+
socket.on("error", () => {
|
|
116
|
+
socket.destroy();
|
|
117
|
+
resolve(false);
|
|
118
|
+
});
|
|
119
|
+
socket.connect(port, host);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function cedarDevDispatcherPlugin() {
|
|
123
|
+
return {
|
|
124
|
+
name: "cedar-dev-dispatcher",
|
|
125
|
+
apply: "serve",
|
|
126
|
+
configureServer(server) {
|
|
127
|
+
const cedarConfig = getConfig();
|
|
128
|
+
const apiUrl = cedarConfig.web.apiUrl.replace(/\/$/, "");
|
|
129
|
+
const apiGqlUrl = cedarConfig.web.apiGraphQLUrl ?? apiUrl + "/graphql";
|
|
130
|
+
const apiPort = cedarConfig.api.port;
|
|
131
|
+
const apiHost = cedarConfig.api.host || "127.0.0.1";
|
|
132
|
+
function isApiRequest(url) {
|
|
133
|
+
return url === apiUrl || url.startsWith(apiUrl + "/") || url.startsWith(apiUrl + "?") || url === apiGqlUrl || url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?");
|
|
134
|
+
}
|
|
135
|
+
server.watcher.on("change", (filePath) => {
|
|
136
|
+
if (filePath.startsWith(getPaths().api.src + path.sep)) {
|
|
137
|
+
invalidateDispatcher();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
server.middlewares.use(
|
|
141
|
+
async (req, res, next) => {
|
|
142
|
+
const url = req.url ?? "/";
|
|
143
|
+
if (isViteInternalRequest(url)) {
|
|
144
|
+
return next();
|
|
145
|
+
}
|
|
146
|
+
if (!isApiRequest(url)) {
|
|
147
|
+
return next();
|
|
148
|
+
}
|
|
149
|
+
if (apiServerIsUp === void 0) {
|
|
150
|
+
apiServerIsUp = await checkApiPort(apiHost, apiPort);
|
|
151
|
+
}
|
|
152
|
+
if (apiServerIsUp) {
|
|
153
|
+
return next();
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const dispatcher = await getDispatcher();
|
|
157
|
+
const fetchRequest = await nodeRequestToFetch(req);
|
|
158
|
+
const fetchResponse = await dispatcher.fetch(fetchRequest);
|
|
159
|
+
await fetchResponseToNode(fetchResponse, res);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(
|
|
162
|
+
"[cedar-dev-dispatcher] Error handling API request:",
|
|
163
|
+
err
|
|
164
|
+
);
|
|
165
|
+
if (!res.headersSent) {
|
|
166
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
167
|
+
}
|
|
168
|
+
res.end(
|
|
169
|
+
JSON.stringify(
|
|
170
|
+
{
|
|
171
|
+
errors: [
|
|
172
|
+
{
|
|
173
|
+
message: err instanceof Error ? err.message : "Internal Server Error"
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
null,
|
|
178
|
+
2
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
cedarDevDispatcherPlugin
|
|
189
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface CedarUniversalDeployPluginOptions {
|
|
3
|
+
apiRootPath?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function cedarUniversalDeployPlugin(options?: CedarUniversalDeployPluginOptions): Plugin;
|
|
6
|
+
//# sourceMappingURL=vite-plugin-cedar-universal-deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-universal-deploy.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-universal-deploy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,MAAM,WAAW,iCAAiC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAKD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,iCAAsC,GAC9C,MAAM,CA2CR"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { addEntry, catchAllEntry } from "@universal-deploy/store";
|
|
2
|
+
const VIRTUAL_CEDAR_API = "virtual:cedar-api";
|
|
3
|
+
const RESOLVED_VIRTUAL_CEDAR_API = "\0virtual:cedar-api";
|
|
4
|
+
function cedarUniversalDeployPlugin(options = {}) {
|
|
5
|
+
const { apiRootPath } = options;
|
|
6
|
+
return {
|
|
7
|
+
name: "cedar-universal-deploy",
|
|
8
|
+
apply: "build",
|
|
9
|
+
buildStart() {
|
|
10
|
+
addEntry({
|
|
11
|
+
id: VIRTUAL_CEDAR_API,
|
|
12
|
+
route: "/**"
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
resolveId(id) {
|
|
16
|
+
if (id === catchAllEntry) {
|
|
17
|
+
return RESOLVED_VIRTUAL_CEDAR_API;
|
|
18
|
+
}
|
|
19
|
+
if (id === VIRTUAL_CEDAR_API) {
|
|
20
|
+
return RESOLVED_VIRTUAL_CEDAR_API;
|
|
21
|
+
}
|
|
22
|
+
return void 0;
|
|
23
|
+
},
|
|
24
|
+
load(id) {
|
|
25
|
+
if (id !== RESOLVED_VIRTUAL_CEDAR_API) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
const apiRootPathArg = apiRootPath !== void 0 ? `{ apiRootPath: ${JSON.stringify(apiRootPath)} }` : "undefined";
|
|
29
|
+
return `
|
|
30
|
+
import { buildCedarDispatcher } from '@cedarjs/api-server/udDispatcher';
|
|
31
|
+
const { fetchable } = await buildCedarDispatcher(${apiRootPathArg});
|
|
32
|
+
export default fetchable;
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
cedarUniversalDeployPlugin
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.13871+0dee87603c",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
"require": "./dist/cjs/buildFeServer.js",
|
|
40
40
|
"import": "./dist/buildFeServer.js"
|
|
41
41
|
},
|
|
42
|
+
"./buildUDApiServer": {
|
|
43
|
+
"import": "./dist/buildUDApiServer.js"
|
|
44
|
+
},
|
|
42
45
|
"./build": {
|
|
43
46
|
"import": "./dist/build/build.js",
|
|
44
47
|
"default": "./dist/cjs/build/build.js"
|
|
@@ -72,19 +75,20 @@
|
|
|
72
75
|
"@babel/generator": "7.29.1",
|
|
73
76
|
"@babel/parser": "7.29.2",
|
|
74
77
|
"@babel/traverse": "7.29.0",
|
|
75
|
-
"@cedarjs/api-server": "4.0.0-canary.
|
|
76
|
-
"@cedarjs/auth": "4.0.0-canary.
|
|
77
|
-
"@cedarjs/babel-config": "4.0.0-canary.
|
|
78
|
-
"@cedarjs/context": "4.0.0-canary.
|
|
79
|
-
"@cedarjs/cookie-jar": "4.0.0-canary.
|
|
80
|
-
"@cedarjs/graphql-server": "4.0.0-canary.
|
|
81
|
-
"@cedarjs/internal": "4.0.0-canary.
|
|
82
|
-
"@cedarjs/project-config": "4.0.0-canary.
|
|
83
|
-
"@cedarjs/server-store": "4.0.0-canary.
|
|
84
|
-
"@cedarjs/testing": "4.0.0-canary.
|
|
85
|
-
"@cedarjs/web": "4.0.0-canary.
|
|
78
|
+
"@cedarjs/api-server": "4.0.0-canary.13871",
|
|
79
|
+
"@cedarjs/auth": "4.0.0-canary.13871",
|
|
80
|
+
"@cedarjs/babel-config": "4.0.0-canary.13871",
|
|
81
|
+
"@cedarjs/context": "4.0.0-canary.13871",
|
|
82
|
+
"@cedarjs/cookie-jar": "4.0.0-canary.13871",
|
|
83
|
+
"@cedarjs/graphql-server": "4.0.0-canary.13871",
|
|
84
|
+
"@cedarjs/internal": "4.0.0-canary.13871",
|
|
85
|
+
"@cedarjs/project-config": "4.0.0-canary.13871",
|
|
86
|
+
"@cedarjs/server-store": "4.0.0-canary.13871",
|
|
87
|
+
"@cedarjs/testing": "4.0.0-canary.13871",
|
|
88
|
+
"@cedarjs/web": "4.0.0-canary.13871",
|
|
86
89
|
"@fastify/url-data": "6.0.3",
|
|
87
90
|
"@swc/core": "1.15.30",
|
|
91
|
+
"@universal-deploy/node": "^0.1.6",
|
|
88
92
|
"@vitejs/plugin-react": "4.7.0",
|
|
89
93
|
"@whatwg-node/fetch": "0.10.13",
|
|
90
94
|
"@whatwg-node/server": "0.10.18",
|
|
@@ -134,5 +138,5 @@
|
|
|
134
138
|
"publishConfig": {
|
|
135
139
|
"access": "public"
|
|
136
140
|
},
|
|
137
|
-
"gitHead": "
|
|
141
|
+
"gitHead": "0dee87603cbf1edb678047367320a4efaadcec81"
|
|
138
142
|
}
|