@rebask/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/components/image.d.ts +16 -3
  2. package/dist/components/image.d.ts.map +1 -1
  3. package/dist/components/image.js +50 -68
  4. package/dist/components/link.d.ts.map +1 -1
  5. package/dist/components/link.js +6 -2
  6. package/dist/lib/image-optimization/fetch-remote-image.d.ts +17 -0
  7. package/dist/lib/image-optimization/fetch-remote-image.d.ts.map +1 -0
  8. package/dist/lib/image-optimization/fetch-remote-image.js +157 -0
  9. package/dist/lib/image-optimization/get-img-props.d.ts +3 -5
  10. package/dist/lib/image-optimization/get-img-props.d.ts.map +1 -1
  11. package/dist/lib/image-optimization/get-img-props.js +66 -40
  12. package/dist/lib/image-optimization/handler.d.ts +0 -3
  13. package/dist/lib/image-optimization/handler.d.ts.map +1 -1
  14. package/dist/lib/image-optimization/handler.js +339 -124
  15. package/dist/lib/image-optimization/image-config.d.ts +31 -4
  16. package/dist/lib/image-optimization/image-config.d.ts.map +1 -1
  17. package/dist/lib/image-optimization/image-config.js +6 -0
  18. package/dist/lib/image-optimization/image-error.d.ts +8 -0
  19. package/dist/lib/image-optimization/image-error.d.ts.map +1 -0
  20. package/dist/lib/image-optimization/image-error.js +10 -0
  21. package/dist/lib/image-optimization/image-plugin.d.ts.map +1 -1
  22. package/dist/lib/image-optimization/image-plugin.js +27 -14
  23. package/dist/lib/image-optimization/is-private-ip.d.ts +2 -0
  24. package/dist/lib/image-optimization/is-private-ip.d.ts.map +1 -0
  25. package/dist/lib/image-optimization/is-private-ip.js +43 -0
  26. package/dist/lib/image-optimization/match-patterns.d.ts +4 -0
  27. package/dist/lib/image-optimization/match-patterns.d.ts.map +1 -0
  28. package/dist/lib/image-optimization/match-patterns.js +39 -0
  29. package/dist/lib/image-optimization/read-body.d.ts +2 -0
  30. package/dist/lib/image-optimization/read-body.d.ts.map +1 -0
  31. package/dist/lib/image-optimization/read-body.js +27 -0
  32. package/dist/lib/image-optimization/static-image-loader.d.ts +2 -0
  33. package/dist/lib/image-optimization/static-image-loader.d.ts.map +1 -0
  34. package/dist/lib/image-optimization/static-image-loader.js +60 -0
  35. package/dist/lib/server-router/build-entries.d.ts.map +1 -1
  36. package/dist/lib/server-router/route-entries.js +1 -1
  37. package/dist/vite.d.ts.map +1 -1
  38. package/dist/vite.js +12 -4
  39. package/package.json +2 -1
  40. package/dist/__type_probe__.d.ts +0 -2
  41. package/dist/__type_probe__.d.ts.map +0 -1
  42. package/dist/__type_probe__.js +0 -4
  43. package/dist/components/error-boundary-client.d.ts +0 -49
  44. package/dist/components/error-boundary-client.d.ts.map +0 -1
  45. package/dist/components/error-boundary-client.js +0 -71
  46. package/dist/components/error-boundary.browser.d.ts +0 -8
  47. package/dist/components/error-boundary.browser.d.ts.map +0 -1
  48. package/dist/components/error-boundary.browser.js +0 -6
  49. package/dist/components/error.d.ts +0 -2
  50. package/dist/components/error.d.ts.map +0 -1
  51. package/dist/components/error.js +0 -5
  52. package/dist/components/not-found-activator.d.ts +0 -11
  53. package/dist/components/not-found-activator.d.ts.map +0 -1
  54. package/dist/components/not-found-activator.js +0 -26
  55. package/dist/components/not-found-boundary-client.d.ts +0 -3
  56. package/dist/components/not-found-boundary-client.d.ts.map +0 -1
  57. package/dist/components/not-found-boundary-client.js +0 -20
  58. package/dist/components/not-found-boundary.browser.d.ts +0 -8
  59. package/dist/components/not-found-boundary.browser.d.ts.map +0 -1
  60. package/dist/components/not-found-boundary.browser.js +0 -4
  61. package/dist/components/not-found-boundary.d.ts +0 -8
  62. package/dist/components/not-found-boundary.d.ts.map +0 -1
  63. package/dist/components/not-found-boundary.js +0 -9
  64. package/dist/components/not-found-thrower.d.ts +0 -2
  65. package/dist/components/not-found-thrower.d.ts.map +0 -1
  66. package/dist/components/not-found-thrower.js +0 -7
  67. package/dist/components/not-found.d.ts +0 -2
  68. package/dist/components/not-found.d.ts.map +0 -1
  69. package/dist/components/not-found.js +0 -5
  70. package/dist/components/status-page.d.ts +0 -6
  71. package/dist/components/status-page.d.ts.map +0 -1
  72. package/dist/components/status-page.js +0 -61
  73. package/dist/handler.d.ts +0 -12
  74. package/dist/handler.d.ts.map +0 -1
  75. package/dist/handler.js +0 -21
  76. package/dist/handlers/rsc/constants.d.ts +0 -3
  77. package/dist/handlers/rsc/constants.d.ts.map +0 -1
  78. package/dist/handlers/rsc/constants.js +0 -2
  79. package/dist/handlers/rsc/create-response.d.ts +0 -3
  80. package/dist/handlers/rsc/create-response.d.ts.map +0 -1
  81. package/dist/handlers/rsc/create-response.js +0 -378
  82. package/dist/handlers/rsc/render-with-retries.d.ts +0 -4
  83. package/dist/handlers/rsc/render-with-retries.d.ts.map +0 -1
  84. package/dist/handlers/rsc/render-with-retries.js +0 -154
  85. package/dist/handlers/rsc/retry-loop.d.ts +0 -3
  86. package/dist/handlers/rsc/retry-loop.d.ts.map +0 -1
  87. package/dist/handlers/rsc/retry-loop.js +0 -145
  88. package/dist/handlers/rsc/stream-rsc-payload.d.ts +0 -9
  89. package/dist/handlers/rsc/stream-rsc-payload.d.ts.map +0 -1
  90. package/dist/handlers/rsc/stream-rsc-payload.js +0 -20
  91. package/dist/handlers/rsc/types.d.ts +0 -26
  92. package/dist/handlers/rsc/types.d.ts.map +0 -1
  93. package/dist/handlers/rsc/types.js +0 -7
  94. package/dist/handlers/rsc.d.ts +0 -20
  95. package/dist/handlers/rsc.d.ts.map +0 -1
  96. package/dist/handlers/rsc.js +0 -872
  97. package/dist/integration.d.ts +0 -14
  98. package/dist/integration.d.ts.map +0 -1
  99. package/dist/integration.js +0 -9
  100. package/dist/lib/dev-module-load-race.d.ts +0 -8
  101. package/dist/lib/dev-module-load-race.d.ts.map +0 -1
  102. package/dist/lib/dev-module-load-race.js +0 -31
  103. package/dist/lib/dev-page-exports.d.ts +0 -5
  104. package/dist/lib/dev-page-exports.d.ts.map +0 -1
  105. package/dist/lib/dev-page-exports.js +0 -14
  106. package/dist/lib/environment-names.d.ts +0 -11
  107. package/dist/lib/environment-names.d.ts.map +0 -1
  108. package/dist/lib/environment-names.js +0 -10
  109. package/dist/lib/initial-hash-scroll.d.ts.map +0 -1
  110. package/dist/lib/not-found.d.ts +0 -5
  111. package/dist/lib/not-found.d.ts.map +0 -1
  112. package/dist/lib/not-found.js +0 -7
  113. package/dist/lib/page-exports.d.ts +0 -9
  114. package/dist/lib/page-exports.d.ts.map +0 -1
  115. package/dist/lib/page-exports.js +0 -47
  116. package/dist/lib/pattern-segments.d.ts +0 -8
  117. package/dist/lib/pattern-segments.d.ts.map +0 -1
  118. package/dist/lib/pattern-segments.js +0 -22
  119. package/dist/lib/ppr/cache-status.d.ts +0 -3
  120. package/dist/lib/ppr/cache-status.d.ts.map +0 -1
  121. package/dist/lib/ppr/cache-status.js +0 -5
  122. package/dist/lib/server-router-contract.d.ts +0 -42
  123. package/dist/lib/server-router-contract.d.ts.map +0 -1
  124. package/dist/lib/server-router-contract.js +0 -6
  125. package/dist/lib/server-router-loader.d.ts +0 -10
  126. package/dist/lib/server-router-loader.d.ts.map +0 -1
  127. package/dist/lib/server-router-loader.js +0 -180
  128. package/dist/lib/server-router.d.ts +0 -8
  129. package/dist/lib/server-router.d.ts.map +0 -1
  130. package/dist/lib/server-router.js +0 -173
  131. package/dist/plugins/ppr-upgrade.d.ts +0 -36
  132. package/dist/plugins/ppr-upgrade.d.ts.map +0 -1
  133. package/dist/plugins/ppr-upgrade.js +0 -32
  134. package/dist/plugins/server-router-fallback.d.ts +0 -15
  135. package/dist/plugins/server-router-fallback.d.ts.map +0 -1
  136. package/dist/plugins/server-router-fallback.js +0 -30
  137. package/dist/server.d.ts +0 -10
  138. package/dist/server.d.ts.map +0 -1
  139. package/dist/server.js +0 -57
@@ -1,173 +0,0 @@
1
- import { layoutRoutes as configLayoutRoutes, routeHandlerRoutes as configRouteHandlerRoutes, routes as configRoutes, } from "virtual:rebask/config";
2
- import { imageConfig } from "virtual:rebask/image-config";
3
- import { loadImageHandler } from "virtual:rebask/image-handler";
4
- import { proxyRouter } from "virtual:rebask/proxy-router";
5
- import { createMatcher } from "virtual:rebask/server-router";
6
- import { applyCookies, getSetCookieValues } from "../cookies.js";
7
- import { handleImageRequest } from "../handlers/image.js";
8
- import { handleRouteHandler } from "../handlers/route-handler.js";
9
- import { handlePageRoute } from "../handlers/rsc/index.js";
10
- import { handleLayoutRouteRequest } from "../handlers/segment.js";
11
- import { getDevServer } from "./dev-server.js";
12
- import { reinjectFlightHeaders, sanitizeForProxy } from "./flight-headers.js";
13
- import { buildProxy } from "./proxy/build-proxy.js";
14
- import { proxyExternal } from "./proxy/proxy-external.js";
15
- import { REWRITE_HEADER, rewriteHeaders } from "./proxy/rewrite.js";
16
- import { assertNoPageRouteHandlerConflicts, buildLayoutRoutes, buildRouteHandlerRoutes, buildRoutes, } from "./route-builder.js";
17
- import { HTTP_METHODS, } from "./route-matcher.js";
18
- import { RouteType } from "./server-router-contract.js";
19
- function buildMainEntries(pageRoutes, routeHandlerRoutes, layoutRoutes) {
20
- const entries = [];
21
- // Image optimization route
22
- if (imageConfig !== null && loadImageHandler !== undefined) {
23
- entries.push({
24
- type: RouteType.IMAGE,
25
- methods: ["GET"],
26
- pattern: imageConfig.path,
27
- handler: handleImageRequest,
28
- });
29
- }
30
- // Page routes — registered for GET and POST:
31
- // - GET: page loads, RSC requests, segment requests
32
- // - POST: server actions, form submissions, PPR resume
33
- for (const route of pageRoutes) {
34
- entries.push({
35
- type: RouteType.APP,
36
- methods: ["GET", "POST"],
37
- route,
38
- handler: (req, params) => handlePageRoute(req, route, params),
39
- });
40
- }
41
- // Route handlers — registered for all methods so they can return 405 when the path exists but a
42
- // specific method is not implemented.
43
- for (const route of routeHandlerRoutes) {
44
- entries.push({
45
- type: RouteType.APP,
46
- methods: [...HTTP_METHODS],
47
- route,
48
- handler: (req, params) => handleRouteHandler(req, route, params),
49
- });
50
- }
51
- // Layout routes — registered under /_rebask/1/{path}
52
- for (const route of layoutRoutes) {
53
- const segments = [
54
- { type: "static", value: "_rebask" },
55
- { type: "static", value: "1" },
56
- ...route.segments,
57
- ];
58
- entries.push({
59
- type: RouteType.APP,
60
- methods: ["GET"],
61
- route: { ...route, segments },
62
- handler: (req, params) => handleLayoutRouteRequest(req, route, params),
63
- });
64
- }
65
- return entries;
66
- }
67
- function buildMainRouter(pageRoutes, routeHandlerRoutes, layoutRoutes) {
68
- const entries = buildMainEntries(pageRoutes, routeHandlerRoutes, layoutRoutes);
69
- const matcher = createMatcher(entries);
70
- return {
71
- find(request) {
72
- const match = matcher.find(request.method, request.url);
73
- if (!match)
74
- return notFoundHandler;
75
- return match;
76
- },
77
- };
78
- }
79
- async function notFoundHandler() {
80
- return new Response("Not Found", { status: 404 });
81
- }
82
- function createRouter(pageRoutes, routeHandlerRoutes, layoutRoutes, resolvedProxyRouter = proxyRouter) {
83
- const mainRouter = buildMainRouter(pageRoutes, routeHandlerRoutes, layoutRoutes);
84
- if (!resolvedProxyRouter)
85
- return mainRouter;
86
- // Compose proxy + main router
87
- return {
88
- find(request) {
89
- const proxyHandler = resolvedProxyRouter.find(request);
90
- if (proxyHandler) {
91
- return async (req) => {
92
- const { sanitized, stashed } = sanitizeForProxy(req);
93
- const result = await proxyHandler(sanitized);
94
- if (result) {
95
- const rewriteUrl = result.headers.get(REWRITE_HEADER);
96
- if (rewriteUrl) {
97
- const rewrittenUrl = new URL(rewriteUrl, req.url);
98
- const reqOrigin = new URL(req.url).origin;
99
- let response;
100
- if (rewrittenUrl.origin !== reqOrigin) {
101
- response = await proxyExternal(rewrittenUrl, req, result, stashed);
102
- }
103
- else {
104
- const mergedHeaders = new Headers(rewriteHeaders.get(result) ?? req.headers);
105
- reinjectFlightHeaders(mergedHeaders, stashed);
106
- // Always restore the `accept` header from the original request. The proxy must not
107
- // be able to change whether a request is treated as HTML or RSC.
108
- const accept = req.headers.get("accept");
109
- if (accept)
110
- mergedHeaders.set("accept", accept);
111
- // Build from URL string instead of `new Request(req, init)`. undici's Request uses
112
- // a private `#state` field, and `new Request` reads it from the existing request,
113
- // which fails when that request was created by a different undici module instance.
114
- const init = { headers: mergedHeaders, method: req.method };
115
- // Only pass the body for methods that support one, passing a stream for GET/HEAD
116
- // throws and would lock the original body.
117
- if (req.body && req.method !== "GET" && req.method !== "HEAD") {
118
- init.body = req.body;
119
- // @ts-expect-error - required for streaming body in Node.js
120
- init.duplex = "half";
121
- }
122
- const rewrittenReq = new Request(rewrittenUrl, init);
123
- const mainHandler = mainRouter.find(rewrittenReq);
124
- response = await mainHandler(rewrittenReq);
125
- }
126
- for (const cookie of getSetCookieValues(result.headers)) {
127
- response.headers.append("set-cookie", cookie);
128
- }
129
- return response;
130
- }
131
- return applyCookies(result);
132
- }
133
- // Fall through with the original request.
134
- const mainHandler = mainRouter.find(req);
135
- return mainHandler(req);
136
- };
137
- }
138
- return mainRouter.find(request);
139
- },
140
- };
141
- }
142
- // In production, build the router at module load time
143
- const router = import.meta.env.PROD
144
- ? createRouter(configRoutes, configRouteHandlerRoutes, configLayoutRoutes)
145
- : null;
146
- /**
147
- * Imports app manifest files through the dev server, without this our HMR tests for the proxy
148
- * don't work.
149
- */
150
- async function loadAppManifest() {
151
- const devServer = getDevServer();
152
- if (devServer) {
153
- const appManifest = await devServer.ssrLoadModule(new URL("./app-manifest.js", import.meta.url).pathname);
154
- return appManifest;
155
- }
156
- return await import("./app-manifest.js");
157
- }
158
- /** Get the compiled server router for route matching. */
159
- export async function getRouter() {
160
- if (router)
161
- return router;
162
- // Development: build routes from module manifest
163
- const { layoutModules, pageModules, proxyModules, routeHandlerModules } = await loadAppManifest();
164
- const layouts = Object.keys(layoutModules);
165
- const pages = Object.keys(pageModules);
166
- assertNoPageRouteHandlerConflicts(pages, Object.keys(routeHandlerModules));
167
- const routes = buildRoutes(layouts, pages);
168
- const routeHandlerRoutes = buildRouteHandlerRoutes(Object.keys(routeHandlerModules));
169
- const layoutRoutes = buildLayoutRoutes(layouts);
170
- const proxyModule = await Object.values(proxyModules)[0]?.();
171
- const proxyRouterInDev = proxyModule && buildProxy(proxyModule.default);
172
- return createRouter(routes, routeHandlerRoutes, layoutRoutes, proxyRouterInDev);
173
- }
@@ -1,36 +0,0 @@
1
- import type { Plugin } from "vite";
2
- /** The `name` of the Vite plugin. */
3
- export declare const REBASK_PPR_UPGRADE_PLUGIN_NAME = "rebask:ppr-upgrade";
4
- export interface PprUpgradeConfig {
5
- /**
6
- * Rebask only enters the resume path when this header matches `"1"`. Adapters must validate
7
- * their own transport credential and set this header before the Rebask handler executes.
8
- */
9
- resumeHeader?: string;
10
- /**
11
- * Header set by the adapter wrapper on any non-resume runtime invocation that should render to
12
- * completion and emit the full HTML (no Suspense streaming).
13
- */
14
- upgradeHeader: string;
15
- /**
16
- * Header emitted on a resume whose shell says that no upgrade is allowed. Adapters can use this
17
- * header to decide if they should do an upgrade request.
18
- */
19
- noUpgradeHeader?: string;
20
- /**
21
- * Content type for an upgrade that produced a shell instead of a full page. The body is the
22
- * serialized postponed state followed by the shell HTML, and `{stateLength}` is replaced with
23
- * the length of that state so the platform can split the two back apart.
24
- */
25
- shellContentType: string;
26
- }
27
- export interface RebaskPprUpgradePluginApi {
28
- /** Opt-in to the partial-fallback shell-upgrade behavior. Passing `null` disables. */
29
- enable: (config: PprUpgradeConfig | null) => void;
30
- }
31
- /**
32
- * Manages the PPR partial-fallback shell-upgrade config. Adapters can use its `api`
33
- * (`RebaskPprUpgradePluginApi`) to opt a deployment target into shell-upgrade behavior.
34
- */
35
- export declare function pprUpgradePlugin(): Plugin;
36
- //# sourceMappingURL=ppr-upgrade.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ppr-upgrade.d.ts","sourceRoot":"","sources":["../../src/plugins/ppr-upgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,qCAAqC;AACrC,eAAO,MAAM,8BAA8B,uBAAuB,CAAA;AAElE,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,yBAAyB;IACzC,sFAAsF;IACtF,MAAM,EAAE,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAA;CACjD;AAKD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAuBzC"}
@@ -1,32 +0,0 @@
1
- /** The `name` of the Vite plugin. */
2
- export const REBASK_PPR_UPGRADE_PLUGIN_NAME = "rebask:ppr-upgrade";
3
- const VIRTUAL_MODULE_ID = "virtual:rebask/ppr-upgrade-config";
4
- const RESOLVED_MODULE_ID = "\0virtual:rebask/ppr-upgrade-config";
5
- /**
6
- * Manages the PPR partial-fallback shell-upgrade config. Adapters can use its `api`
7
- * (`RebaskPprUpgradePluginApi`) to opt a deployment target into shell-upgrade behavior.
8
- */
9
- export function pprUpgradePlugin() {
10
- let enabledConfig = null;
11
- const api = {
12
- enable(config) {
13
- enabledConfig = config;
14
- },
15
- };
16
- return {
17
- name: REBASK_PPR_UPGRADE_PLUGIN_NAME,
18
- api,
19
- resolveId(id) {
20
- if (id === VIRTUAL_MODULE_ID)
21
- return RESOLVED_MODULE_ID;
22
- },
23
- load(id) {
24
- if (id !== RESOLVED_MODULE_ID)
25
- return;
26
- if (enabledConfig === null) {
27
- return `export const pprUpgradeConfig = null;`;
28
- }
29
- return `export const pprUpgradeConfig = ${JSON.stringify(enabledConfig)};`;
30
- },
31
- };
32
- }
@@ -1,15 +0,0 @@
1
- import type { Plugin } from "vite";
2
- /**
3
- * Fallback plugin that resolves `virtual:rebask/server-router` to the
4
- * in-package wint matcher.
5
- *
6
- * Uses `enforce: "post"` so that an explicit router plugin (e.g.
7
- * `rebaskRouter()` or `rebaskNitro()`) with normal enforce can resolve the
8
- * virtual module first. When that happens, this plugin's `load` never runs
9
- * and the wint code never enters the module graph — it is tree-shaken out.
10
- *
11
- * This mirrors the existing `rebask:cache-handler-fallback` and
12
- * `rebask:image-config-fallback` patterns.
13
- */
14
- export declare function serverRouterFallbackPlugin(): Plugin;
15
- //# sourceMappingURL=server-router-fallback.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server-router-fallback.d.ts","sourceRoot":"","sources":["../../src/plugins/server-router-fallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAenD"}
@@ -1,30 +0,0 @@
1
- const VIRTUAL_MODULE_ID = "virtual:rebask/server-router";
2
- const RESOLVED_MODULE_ID = "\0virtual:rebask/server-router";
3
- /**
4
- * Fallback plugin that resolves `virtual:rebask/server-router` to the
5
- * in-package wint matcher.
6
- *
7
- * Uses `enforce: "post"` so that an explicit router plugin (e.g.
8
- * `rebaskRouter()` or `rebaskNitro()`) with normal enforce can resolve the
9
- * virtual module first. When that happens, this plugin's `load` never runs
10
- * and the wint code never enters the module graph — it is tree-shaken out.
11
- *
12
- * This mirrors the existing `rebask:cache-handler-fallback` and
13
- * `rebask:image-config-fallback` patterns.
14
- */
15
- export function serverRouterFallbackPlugin() {
16
- return {
17
- name: "rebask:server-router-fallback",
18
- enforce: "post",
19
- resolveId(id) {
20
- if (id === VIRTUAL_MODULE_ID)
21
- return RESOLVED_MODULE_ID;
22
- },
23
- load(id) {
24
- if (id !== RESOLVED_MODULE_ID)
25
- return;
26
- const routerWintPath = new URL("../lib/router-wint.js", import.meta.url).pathname;
27
- return `export { createMatcher } from ${JSON.stringify(routerWintPath)};`;
28
- },
29
- };
30
- }
package/dist/server.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface CreateServerOptions {
2
- /** Vite build output directory. */
3
- root: string | URL;
4
- }
5
- export interface RebaskServer {
6
- fetch(request: Request): Promise<Response>;
7
- }
8
- /** Create a Node-side fetch handler for a production build. */
9
- export declare function createServer(options: CreateServerOptions): Promise<RebaskServer>;
10
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IACnC,mCAAmC;IACnC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC1C;AAgDD,+DAA+D;AAC/D,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAmBtF"}
package/dist/server.js DELETED
@@ -1,57 +0,0 @@
1
- import { readFile, stat } from "node:fs/promises";
2
- import { extname, join, resolve, sep } from "node:path";
3
- import { fileURLToPath, pathToFileURL } from "node:url";
4
- const CONTENT_TYPES = {
5
- ".css": "text/css; charset=utf-8",
6
- ".html": "text/html; charset=utf-8",
7
- ".ico": "image/x-icon",
8
- ".jpg": "image/jpeg",
9
- ".jpeg": "image/jpeg",
10
- ".js": "text/javascript; charset=utf-8",
11
- ".json": "application/json; charset=utf-8",
12
- ".map": "application/json; charset=utf-8",
13
- ".png": "image/png",
14
- ".svg": "image/svg+xml",
15
- ".txt": "text/plain; charset=utf-8",
16
- ".webp": "image/webp",
17
- ".woff": "font/woff",
18
- ".woff2": "font/woff2",
19
- };
20
- function toPath(value) {
21
- return value instanceof URL ? fileURLToPath(value) : resolve(value);
22
- }
23
- async function serveStatic(request, clientDir) {
24
- if (request.method !== "GET" && request.method !== "HEAD")
25
- return null;
26
- const pathname = decodeURIComponent(new URL(request.url).pathname);
27
- const relative = pathname.endsWith("/") ? `${pathname}index.html` : pathname;
28
- const filePath = join(clientDir, relative);
29
- if (filePath !== clientDir && !filePath.startsWith(clientDir + sep))
30
- return null;
31
- const file = await stat(filePath).catch(() => null);
32
- if (!file?.isFile())
33
- return null;
34
- const headers = {
35
- "content-type": CONTENT_TYPES[extname(filePath)] ?? "application/octet-stream",
36
- "content-length": String(file.size),
37
- };
38
- return new Response(request.method === "HEAD" ? null : await readFile(filePath), { headers });
39
- }
40
- /** Create a Node-side fetch handler for a production build. */
41
- export async function createServer(options) {
42
- const root = toPath(options.root);
43
- const clientDir = join(root, "client");
44
- process.env.REBASK_BUILD_DIR = join(root, ".rebask");
45
- const entry = (await import(pathToFileURL(join(root, "rsc", "index.js")).href));
46
- return {
47
- async fetch(request) {
48
- const proxyResponse = await entry.handleProxy(request);
49
- if (proxyResponse)
50
- return proxyResponse;
51
- const staticResponse = await serveStatic(request, clientDir);
52
- if (staticResponse)
53
- return staticResponse;
54
- return entry.handleApp(request);
55
- },
56
- };
57
- }