@react-router/cloudflare 0.0.0-experimental-8cee090e4 → 0.0.0-experimental-dd63c14ca
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/index.d.mts +53 -0
- package/dist/index.d.ts +31 -45
- package/dist/index.js +145 -81
- package/dist/index.mjs +129 -0
- package/package.json +17 -12
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage, ServerBuild, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext } from 'react-router';
|
|
2
|
+
import { CacheStorage } from '@cloudflare/workers-types';
|
|
3
|
+
|
|
4
|
+
interface WorkersKVSessionStorageOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The Cookie used to store the session id on the client, or options used
|
|
7
|
+
* to automatically create one.
|
|
8
|
+
*/
|
|
9
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
10
|
+
/**
|
|
11
|
+
* The KVNamespace used to store the sessions.
|
|
12
|
+
*/
|
|
13
|
+
kv: KVNamespace;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a SessionStorage that stores session data in the Clouldflare KV Store.
|
|
17
|
+
*
|
|
18
|
+
* The advantage of using this instead of cookie session storage is that
|
|
19
|
+
* KV Store may contain much more data than cookies.
|
|
20
|
+
*/
|
|
21
|
+
declare function createWorkersKVSessionStorage<Data = SessionData, FlashData = Data>({ cookie, kv, }: WorkersKVSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
22
|
+
|
|
23
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* A function that returns the value to use as `context` in route `loader` and
|
|
26
|
+
* `action` functions.
|
|
27
|
+
*
|
|
28
|
+
* You can think of this as an escape hatch that allows you to pass
|
|
29
|
+
* environment/platform-specific values through to your loader/action.
|
|
30
|
+
*/
|
|
31
|
+
type GetLoadContextFunction<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>> = (args: {
|
|
32
|
+
request: Request;
|
|
33
|
+
context: {
|
|
34
|
+
cloudflare: EventContext<Env, Params, Data> & {
|
|
35
|
+
cf: EventContext<Env, Params, Data>["request"]["cf"];
|
|
36
|
+
ctx: {
|
|
37
|
+
waitUntil: EventContext<Env, Params, Data>["waitUntil"];
|
|
38
|
+
passThroughOnException: EventContext<Env, Params, Data>["passThroughOnException"];
|
|
39
|
+
};
|
|
40
|
+
caches: CacheStorage;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}) => UNSAFE_MiddlewareEnabled extends true ? MaybePromise<RouterContextProvider> : MaybePromise<AppLoadContext>;
|
|
44
|
+
type RequestHandler<Env = any> = PagesFunction<Env>;
|
|
45
|
+
interface createPagesFunctionHandlerParams<Env = any> {
|
|
46
|
+
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>);
|
|
47
|
+
getLoadContext?: GetLoadContextFunction<Env>;
|
|
48
|
+
mode?: string;
|
|
49
|
+
}
|
|
50
|
+
declare function createRequestHandler<Env = any>({ build, mode, getLoadContext, }: createPagesFunctionHandlerParams<Env>): RequestHandler<Env>;
|
|
51
|
+
declare function createPagesFunctionHandler<Env = any>({ build, getLoadContext, mode, }: createPagesFunctionHandlerParams<Env>): (context: EventContext<Env, any, any>) => Promise<Response>;
|
|
52
|
+
|
|
53
|
+
export { type GetLoadContextFunction, type RequestHandler, createPagesFunctionHandler, type createPagesFunctionHandlerParams, createRequestHandler, createWorkersKVSessionStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage, ServerBuild, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext } from 'react-router';
|
|
2
|
+
import { CacheStorage } from '@cloudflare/workers-types';
|
|
1
3
|
|
|
2
|
-
import { RouterContextProvider, ServerBuild, SessionData, SessionIdStorageStrategy, SessionStorage } from "react-router";
|
|
3
|
-
import { CacheStorage } from "@cloudflare/workers-types";
|
|
4
|
-
|
|
5
|
-
//#region sessions/workersKVStorage.d.ts
|
|
6
4
|
interface WorkersKVSessionStorageOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The Cookie used to store the session id on the client, or options used
|
|
7
|
+
* to automatically create one.
|
|
8
|
+
*/
|
|
9
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
10
|
+
/**
|
|
11
|
+
* The KVNamespace used to store the sessions.
|
|
12
|
+
*/
|
|
13
|
+
kv: KVNamespace;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Creates a SessionStorage that stores session data in the Clouldflare KV Store.
|
|
@@ -20,12 +18,8 @@ interface WorkersKVSessionStorageOptions {
|
|
|
20
18
|
* The advantage of using this instead of cookie session storage is that
|
|
21
19
|
* KV Store may contain much more data than cookies.
|
|
22
20
|
*/
|
|
23
|
-
declare function createWorkersKVSessionStorage<Data = SessionData, FlashData = Data>({
|
|
24
|
-
|
|
25
|
-
kv
|
|
26
|
-
}: WorkersKVSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region worker.d.ts
|
|
21
|
+
declare function createWorkersKVSessionStorage<Data = SessionData, FlashData = Data>({ cookie, kv, }: WorkersKVSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
22
|
+
|
|
29
23
|
type MaybePromise<T> = T | Promise<T>;
|
|
30
24
|
/**
|
|
31
25
|
* A function that returns the value to use as `context` in route `loader` and
|
|
@@ -35,33 +29,25 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
35
29
|
* environment/platform-specific values through to your loader/action.
|
|
36
30
|
*/
|
|
37
31
|
type GetLoadContextFunction<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>> = (args: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
request: Request;
|
|
33
|
+
context: {
|
|
34
|
+
cloudflare: EventContext<Env, Params, Data> & {
|
|
35
|
+
cf: EventContext<Env, Params, Data>["request"]["cf"];
|
|
36
|
+
ctx: {
|
|
37
|
+
waitUntil: EventContext<Env, Params, Data>["waitUntil"];
|
|
38
|
+
passThroughOnException: EventContext<Env, Params, Data>["passThroughOnException"];
|
|
39
|
+
};
|
|
40
|
+
caches: CacheStorage;
|
|
41
|
+
};
|
|
47
42
|
};
|
|
48
|
-
|
|
49
|
-
}) => MaybePromise<RouterContextProvider>;
|
|
43
|
+
}) => UNSAFE_MiddlewareEnabled extends true ? MaybePromise<RouterContextProvider> : MaybePromise<AppLoadContext>;
|
|
50
44
|
type RequestHandler<Env = any> = PagesFunction<Env>;
|
|
51
45
|
interface createPagesFunctionHandlerParams<Env = any> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>);
|
|
47
|
+
getLoadContext?: GetLoadContextFunction<Env>;
|
|
48
|
+
mode?: string;
|
|
55
49
|
}
|
|
56
|
-
declare function createRequestHandler<Env = any>({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}: createPagesFunctionHandlerParams<Env>): RequestHandler<Env>;
|
|
61
|
-
declare function createPagesFunctionHandler<Env = any>({
|
|
62
|
-
build,
|
|
63
|
-
getLoadContext,
|
|
64
|
-
mode
|
|
65
|
-
}: createPagesFunctionHandlerParams<Env>): (context: EventContext<Env, any, any>) => Promise<Response>;
|
|
66
|
-
//#endregion
|
|
67
|
-
export { type GetLoadContextFunction, type RequestHandler, createPagesFunctionHandler, type createPagesFunctionHandlerParams, createRequestHandler, createWorkersKVSessionStorage };
|
|
50
|
+
declare function createRequestHandler<Env = any>({ build, mode, getLoadContext, }: createPagesFunctionHandlerParams<Env>): RequestHandler<Env>;
|
|
51
|
+
declare function createPagesFunctionHandler<Env = any>({ build, getLoadContext, mode, }: createPagesFunctionHandlerParams<Env>): (context: EventContext<Env, any, any>) => Promise<Response>;
|
|
52
|
+
|
|
53
|
+
export { type GetLoadContextFunction, type RequestHandler, createPagesFunctionHandler, type createPagesFunctionHandlerParams, createRequestHandler, createWorkersKVSessionStorage };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/cloudflare v0.0.0-experimental-
|
|
2
|
+
* @react-router/cloudflare v0.0.0-experimental-dd63c14ca
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,86 +8,150 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
"use strict";
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
createPagesFunctionHandler: () => createPagesFunctionHandler,
|
|
34
|
+
createRequestHandler: () => createRequestHandler,
|
|
35
|
+
createWorkersKVSessionStorage: () => createWorkersKVSessionStorage
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// sessions/workersKVStorage.ts
|
|
40
|
+
var import_react_router = require("react-router");
|
|
41
|
+
function createWorkersKVSessionStorage({
|
|
42
|
+
cookie,
|
|
43
|
+
kv
|
|
44
|
+
}) {
|
|
45
|
+
return (0, import_react_router.createSessionStorage)({
|
|
46
|
+
cookie,
|
|
47
|
+
async createData(data, expires) {
|
|
48
|
+
while (true) {
|
|
49
|
+
let randomBytes = crypto.getRandomValues(new Uint8Array(8));
|
|
50
|
+
let id = [...randomBytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
51
|
+
if (await kv.get(id, "json")) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
await kv.put(id, JSON.stringify(data), {
|
|
55
|
+
expiration: expires ? Math.round(expires.getTime() / 1e3) : void 0
|
|
56
|
+
});
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async readData(id) {
|
|
61
|
+
let session = await kv.get(id);
|
|
62
|
+
if (!session) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return JSON.parse(session);
|
|
66
|
+
},
|
|
67
|
+
async updateData(id, data, expires) {
|
|
68
|
+
await kv.put(id, JSON.stringify(data), {
|
|
69
|
+
expiration: expires ? Math.round(expires.getTime() / 1e3) : void 0
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async deleteData(id) {
|
|
73
|
+
await kv.delete(id);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
43
76
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
|
|
78
|
+
// worker.ts
|
|
79
|
+
var import_react_router2 = require("react-router");
|
|
80
|
+
function createRequestHandler({
|
|
81
|
+
build,
|
|
82
|
+
mode,
|
|
83
|
+
getLoadContext = ({ context }) => ({
|
|
84
|
+
...context,
|
|
85
|
+
cloudflare: {
|
|
86
|
+
...context.cloudflare,
|
|
87
|
+
cf: context.cloudflare.request.cf
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}) {
|
|
91
|
+
let handleRequest = (0, import_react_router2.createRequestHandler)(build, mode);
|
|
92
|
+
return async (cloudflare) => {
|
|
93
|
+
let loadContext = await getLoadContext({
|
|
94
|
+
request: cloudflare.request,
|
|
95
|
+
context: {
|
|
96
|
+
cloudflare: {
|
|
97
|
+
...cloudflare,
|
|
98
|
+
cf: cloudflare.request.cf,
|
|
99
|
+
ctx: {
|
|
100
|
+
waitUntil: cloudflare.waitUntil.bind(cloudflare),
|
|
101
|
+
passThroughOnException: cloudflare.passThroughOnException.bind(cloudflare)
|
|
102
|
+
},
|
|
103
|
+
caches
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return handleRequest(cloudflare.request, loadContext);
|
|
108
|
+
};
|
|
63
109
|
}
|
|
64
|
-
function createPagesFunctionHandler({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
110
|
+
function createPagesFunctionHandler({
|
|
111
|
+
build,
|
|
112
|
+
getLoadContext,
|
|
113
|
+
mode
|
|
114
|
+
}) {
|
|
115
|
+
let handleRequest = createRequestHandler({
|
|
116
|
+
build,
|
|
117
|
+
getLoadContext,
|
|
118
|
+
mode
|
|
119
|
+
});
|
|
120
|
+
let handleFetch = async (context) => {
|
|
121
|
+
let response;
|
|
122
|
+
context.request.headers.delete("if-none-match");
|
|
123
|
+
try {
|
|
124
|
+
response = await context.env.ASSETS.fetch(
|
|
125
|
+
context.request.url,
|
|
126
|
+
context.request.clone()
|
|
127
|
+
);
|
|
128
|
+
response = response && response.status >= 200 && response.status < 400 ? new Response(response.body, response) : void 0;
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
if (!response) {
|
|
132
|
+
response = await handleRequest(context);
|
|
133
|
+
}
|
|
134
|
+
return response;
|
|
135
|
+
};
|
|
136
|
+
return async (context) => {
|
|
137
|
+
try {
|
|
138
|
+
return await handleFetch(context);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (process.env.NODE_ENV === "development" && error instanceof Error) {
|
|
141
|
+
console.error(error);
|
|
142
|
+
return new Response(error.message || error.toString(), {
|
|
143
|
+
status: 500
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return new Response("Internal Error", {
|
|
147
|
+
status: 500
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
91
151
|
}
|
|
92
|
-
|
|
93
|
-
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
createPagesFunctionHandler,
|
|
155
|
+
createRequestHandler,
|
|
156
|
+
createWorkersKVSessionStorage
|
|
157
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/cloudflare v0.0.0-experimental-dd63c14ca
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// sessions/workersKVStorage.ts
|
|
13
|
+
import { createSessionStorage } from "react-router";
|
|
14
|
+
function createWorkersKVSessionStorage({
|
|
15
|
+
cookie,
|
|
16
|
+
kv
|
|
17
|
+
}) {
|
|
18
|
+
return createSessionStorage({
|
|
19
|
+
cookie,
|
|
20
|
+
async createData(data, expires) {
|
|
21
|
+
while (true) {
|
|
22
|
+
let randomBytes = crypto.getRandomValues(new Uint8Array(8));
|
|
23
|
+
let id = [...randomBytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
if (await kv.get(id, "json")) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
await kv.put(id, JSON.stringify(data), {
|
|
28
|
+
expiration: expires ? Math.round(expires.getTime() / 1e3) : void 0
|
|
29
|
+
});
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async readData(id) {
|
|
34
|
+
let session = await kv.get(id);
|
|
35
|
+
if (!session) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return JSON.parse(session);
|
|
39
|
+
},
|
|
40
|
+
async updateData(id, data, expires) {
|
|
41
|
+
await kv.put(id, JSON.stringify(data), {
|
|
42
|
+
expiration: expires ? Math.round(expires.getTime() / 1e3) : void 0
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
async deleteData(id) {
|
|
46
|
+
await kv.delete(id);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// worker.ts
|
|
52
|
+
import { createRequestHandler as createReactRouterRequestHandler } from "react-router";
|
|
53
|
+
function createRequestHandler({
|
|
54
|
+
build,
|
|
55
|
+
mode,
|
|
56
|
+
getLoadContext = ({ context }) => ({
|
|
57
|
+
...context,
|
|
58
|
+
cloudflare: {
|
|
59
|
+
...context.cloudflare,
|
|
60
|
+
cf: context.cloudflare.request.cf
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}) {
|
|
64
|
+
let handleRequest = createReactRouterRequestHandler(build, mode);
|
|
65
|
+
return async (cloudflare) => {
|
|
66
|
+
let loadContext = await getLoadContext({
|
|
67
|
+
request: cloudflare.request,
|
|
68
|
+
context: {
|
|
69
|
+
cloudflare: {
|
|
70
|
+
...cloudflare,
|
|
71
|
+
cf: cloudflare.request.cf,
|
|
72
|
+
ctx: {
|
|
73
|
+
waitUntil: cloudflare.waitUntil.bind(cloudflare),
|
|
74
|
+
passThroughOnException: cloudflare.passThroughOnException.bind(cloudflare)
|
|
75
|
+
},
|
|
76
|
+
caches
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return handleRequest(cloudflare.request, loadContext);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function createPagesFunctionHandler({
|
|
84
|
+
build,
|
|
85
|
+
getLoadContext,
|
|
86
|
+
mode
|
|
87
|
+
}) {
|
|
88
|
+
let handleRequest = createRequestHandler({
|
|
89
|
+
build,
|
|
90
|
+
getLoadContext,
|
|
91
|
+
mode
|
|
92
|
+
});
|
|
93
|
+
let handleFetch = async (context) => {
|
|
94
|
+
let response;
|
|
95
|
+
context.request.headers.delete("if-none-match");
|
|
96
|
+
try {
|
|
97
|
+
response = await context.env.ASSETS.fetch(
|
|
98
|
+
context.request.url,
|
|
99
|
+
context.request.clone()
|
|
100
|
+
);
|
|
101
|
+
response = response && response.status >= 200 && response.status < 400 ? new Response(response.body, response) : void 0;
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
if (!response) {
|
|
105
|
+
response = await handleRequest(context);
|
|
106
|
+
}
|
|
107
|
+
return response;
|
|
108
|
+
};
|
|
109
|
+
return async (context) => {
|
|
110
|
+
try {
|
|
111
|
+
return await handleFetch(context);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (process.env.NODE_ENV === "development" && error instanceof Error) {
|
|
114
|
+
console.error(error);
|
|
115
|
+
return new Response(error.message || error.toString(), {
|
|
116
|
+
status: 500
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return new Response("Internal Error", {
|
|
120
|
+
status: 500
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
createPagesFunctionHandler,
|
|
127
|
+
createRequestHandler,
|
|
128
|
+
createWorkersKVSessionStorage
|
|
129
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/cloudflare",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.0-experimental-8cee090e4",
|
|
3
|
+
"version": "0.0.0-experimental-dd63c14ca",
|
|
5
4
|
"description": "Cloudflare platform abstractions for React Router",
|
|
6
5
|
"bugs": {
|
|
7
6
|
"url": "https://github.com/remix-run/react-router/issues"
|
|
@@ -16,14 +15,20 @@
|
|
|
16
15
|
"typings": "dist/index.d.ts",
|
|
17
16
|
"exports": {
|
|
18
17
|
".": {
|
|
19
|
-
"
|
|
20
|
-
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"default": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
21
26
|
},
|
|
22
27
|
"./package.json": "./package.json"
|
|
23
28
|
},
|
|
24
29
|
"wireit": {
|
|
25
30
|
"build": {
|
|
26
|
-
"command": "
|
|
31
|
+
"command": "tsup",
|
|
27
32
|
"files": [
|
|
28
33
|
"../../pnpm-workspace.yaml",
|
|
29
34
|
"sessions/**",
|
|
@@ -37,16 +42,16 @@
|
|
|
37
42
|
}
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
|
-
"@cloudflare/workers-types": "^4.
|
|
41
|
-
"
|
|
42
|
-
"typescript": "^
|
|
43
|
-
"wireit": "0.14.
|
|
44
|
-
"react-router": "0.0.0-experimental-
|
|
45
|
+
"@cloudflare/workers-types": "^4.20250803.0",
|
|
46
|
+
"tsup": "^8.3.0",
|
|
47
|
+
"typescript": "^5.4.5",
|
|
48
|
+
"wireit": "0.14.9",
|
|
49
|
+
"react-router": "0.0.0-experimental-dd63c14ca"
|
|
45
50
|
},
|
|
46
51
|
"peerDependencies": {
|
|
47
52
|
"@cloudflare/workers-types": "^4.0.0",
|
|
48
53
|
"typescript": "^5.1.0 || ^6.0.0",
|
|
49
|
-
"react-router": "^0.0.0-experimental-
|
|
54
|
+
"react-router": "^0.0.0-experimental-dd63c14ca"
|
|
50
55
|
},
|
|
51
56
|
"peerDependenciesMeta": {
|
|
52
57
|
"typescript": {
|
|
@@ -54,7 +59,7 @@
|
|
|
54
59
|
}
|
|
55
60
|
},
|
|
56
61
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
62
|
+
"node": ">=20.0.0"
|
|
58
63
|
},
|
|
59
64
|
"files": [
|
|
60
65
|
"dist/",
|