Skip to content

Commit 42393ce

Browse files
committed
upd
1 parent a5f474f commit 42393ce

42 files changed

Lines changed: 1483 additions & 192 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.wrangler/tmp/bundle-5rCH3B/middleware-insertion-facade.js renamed to .wrangler/tmp/bundle-Gs6nOV/middleware-insertion-facade.js

File renamed without changes.

.wrangler/tmp/bundle-5rCH3B/middleware-loader.entry.ts renamed to .wrangler/tmp/bundle-Gs6nOV/middleware-loader.entry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// export dynamically through wrangler, or we can potentially let users directly
44
// add them as a sort of "plugin" system.
55

6-
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-5rCH3B/middleware-insertion-facade.js";
6+
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-Gs6nOV/middleware-insertion-facade.js";
77
import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/common.ts";
8-
import type { WorkerEntrypointConstructor } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-5rCH3B/middleware-insertion-facade.js";
8+
import type { WorkerEntrypointConstructor } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-Gs6nOV/middleware-insertion-facade.js";
99

1010
// Preserve all the exports from the worker
11-
export * from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-5rCH3B/middleware-insertion-facade.js";
11+
export * from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-Gs6nOV/middleware-insertion-facade.js";
1212

1313
class __Facade_ScheduledController__ implements ScheduledController {
1414
readonly #noRetry: ScheduledController["noRetry"];

.wrangler/tmp/bundle-5rCH3B/strip-cf-connecting-ip-header.js renamed to .wrangler/tmp/bundle-Gs6nOV/strip-cf-connecting-ip-header.js

File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import worker, * as OTHER_EXPORTS from "/Users/songjunxi/Desktop/repos/vmail/worker/src/index.ts";
2+
import * as __MIDDLEWARE_0__ from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3+
import * as __MIDDLEWARE_1__ from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4+
5+
export * from "/Users/songjunxi/Desktop/repos/vmail/worker/src/index.ts";
6+
7+
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8+
9+
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10+
]
11+
export default worker;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This loads all middlewares exposed on the middleware object and then starts
2+
// the invocation chain. The big idea is that we can add these to the middleware
3+
// export dynamically through wrangler, or we can potentially let users directly
4+
// add them as a sort of "plugin" system.
5+
6+
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-MJIuJQ/middleware-insertion-facade.js";
7+
import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/common.ts";
8+
import type { WorkerEntrypointConstructor } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-MJIuJQ/middleware-insertion-facade.js";
9+
10+
// Preserve all the exports from the worker
11+
export * from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-MJIuJQ/middleware-insertion-facade.js";
12+
13+
class __Facade_ScheduledController__ implements ScheduledController {
14+
readonly #noRetry: ScheduledController["noRetry"];
15+
16+
constructor(
17+
readonly scheduledTime: number,
18+
readonly cron: string,
19+
noRetry: ScheduledController["noRetry"]
20+
) {
21+
this.#noRetry = noRetry;
22+
}
23+
24+
noRetry() {
25+
if (!(this instanceof __Facade_ScheduledController__)) {
26+
throw new TypeError("Illegal invocation");
27+
}
28+
// Need to call native method immediately in case uncaught error thrown
29+
this.#noRetry();
30+
}
31+
}
32+
33+
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34+
// If we don't have any middleware defined, just return the handler as is
35+
if (
36+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38+
) {
39+
return worker;
40+
}
41+
// Otherwise, register all middleware once
42+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43+
__facade_register__(middleware);
44+
}
45+
46+
const fetchDispatcher: ExportedHandlerFetchHandler = function (
47+
request,
48+
env,
49+
ctx
50+
) {
51+
if (worker.fetch === undefined) {
52+
throw new Error("Handler does not export a fetch() function.");
53+
}
54+
return worker.fetch(request, env, ctx);
55+
};
56+
57+
return {
58+
...worker,
59+
fetch(request, env, ctx) {
60+
const dispatcher: Dispatcher = function (type, init) {
61+
if (type === "scheduled" && worker.scheduled !== undefined) {
62+
const controller = new __Facade_ScheduledController__(
63+
Date.now(),
64+
init.cron ?? "",
65+
() => {}
66+
);
67+
return worker.scheduled(controller, env, ctx);
68+
}
69+
};
70+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71+
},
72+
};
73+
}
74+
75+
function wrapWorkerEntrypoint(
76+
klass: WorkerEntrypointConstructor
77+
): WorkerEntrypointConstructor {
78+
// If we don't have any middleware defined, just return the handler as is
79+
if (
80+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82+
) {
83+
return klass;
84+
}
85+
// Otherwise, register all middleware once
86+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87+
__facade_register__(middleware);
88+
}
89+
90+
// `extend`ing `klass` here so other RPC methods remain callable
91+
return class extends klass {
92+
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93+
request,
94+
env,
95+
ctx
96+
) => {
97+
this.env = env;
98+
this.ctx = ctx;
99+
if (super.fetch === undefined) {
100+
throw new Error("Entrypoint class does not define a fetch() function.");
101+
}
102+
return super.fetch(request);
103+
};
104+
105+
#dispatcher: Dispatcher = (type, init) => {
106+
if (type === "scheduled" && super.scheduled !== undefined) {
107+
const controller = new __Facade_ScheduledController__(
108+
Date.now(),
109+
init.cron ?? "",
110+
() => {}
111+
);
112+
return super.scheduled(controller);
113+
}
114+
};
115+
116+
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117+
return __facade_invoke__(
118+
request,
119+
this.env,
120+
this.ctx,
121+
this.#dispatcher,
122+
this.#fetchDispatcher
123+
);
124+
}
125+
};
126+
}
127+
128+
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129+
if (typeof ENTRY === "object") {
130+
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131+
} else if (typeof ENTRY === "function") {
132+
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133+
}
134+
export default WRAPPED_ENTRY;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function stripCfConnectingIPHeader(input, init) {
2+
const request = new Request(input, init);
3+
request.headers.delete("CF-Connecting-IP");
4+
return request;
5+
}
6+
7+
globalThis.fetch = new Proxy(globalThis.fetch, {
8+
apply(target, thisArg, argArray) {
9+
return Reflect.apply(target, thisArg, [
10+
stripCfConnectingIPHeader.apply(null, argArray),
11+
]);
12+
},
13+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import worker, * as OTHER_EXPORTS from "/Users/songjunxi/Desktop/repos/vmail/worker/src/index.ts";
2+
import * as __MIDDLEWARE_0__ from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts";
3+
import * as __MIDDLEWARE_1__ from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts";
4+
5+
export * from "/Users/songjunxi/Desktop/repos/vmail/worker/src/index.ts";
6+
7+
export const __INTERNAL_WRANGLER_MIDDLEWARE__ = [
8+
9+
__MIDDLEWARE_0__.default,__MIDDLEWARE_1__.default
10+
]
11+
export default worker;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This loads all middlewares exposed on the middleware object and then starts
2+
// the invocation chain. The big idea is that we can add these to the middleware
3+
// export dynamically through wrangler, or we can potentially let users directly
4+
// add them as a sort of "plugin" system.
5+
6+
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-SY4zl5/middleware-insertion-facade.js";
7+
import { __facade_invoke__, __facade_register__, Dispatcher } from "/Users/songjunxi/Desktop/repos/vmail/node_modules/.pnpm/wrangler@3.114.15/node_modules/wrangler/templates/middleware/common.ts";
8+
import type { WorkerEntrypointConstructor } from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-SY4zl5/middleware-insertion-facade.js";
9+
10+
// Preserve all the exports from the worker
11+
export * from "/Users/songjunxi/Desktop/repos/vmail/.wrangler/tmp/bundle-SY4zl5/middleware-insertion-facade.js";
12+
13+
class __Facade_ScheduledController__ implements ScheduledController {
14+
readonly #noRetry: ScheduledController["noRetry"];
15+
16+
constructor(
17+
readonly scheduledTime: number,
18+
readonly cron: string,
19+
noRetry: ScheduledController["noRetry"]
20+
) {
21+
this.#noRetry = noRetry;
22+
}
23+
24+
noRetry() {
25+
if (!(this instanceof __Facade_ScheduledController__)) {
26+
throw new TypeError("Illegal invocation");
27+
}
28+
// Need to call native method immediately in case uncaught error thrown
29+
this.#noRetry();
30+
}
31+
}
32+
33+
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
34+
// If we don't have any middleware defined, just return the handler as is
35+
if (
36+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
37+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
38+
) {
39+
return worker;
40+
}
41+
// Otherwise, register all middleware once
42+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
43+
__facade_register__(middleware);
44+
}
45+
46+
const fetchDispatcher: ExportedHandlerFetchHandler = function (
47+
request,
48+
env,
49+
ctx
50+
) {
51+
if (worker.fetch === undefined) {
52+
throw new Error("Handler does not export a fetch() function.");
53+
}
54+
return worker.fetch(request, env, ctx);
55+
};
56+
57+
return {
58+
...worker,
59+
fetch(request, env, ctx) {
60+
const dispatcher: Dispatcher = function (type, init) {
61+
if (type === "scheduled" && worker.scheduled !== undefined) {
62+
const controller = new __Facade_ScheduledController__(
63+
Date.now(),
64+
init.cron ?? "",
65+
() => {}
66+
);
67+
return worker.scheduled(controller, env, ctx);
68+
}
69+
};
70+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
71+
},
72+
};
73+
}
74+
75+
function wrapWorkerEntrypoint(
76+
klass: WorkerEntrypointConstructor
77+
): WorkerEntrypointConstructor {
78+
// If we don't have any middleware defined, just return the handler as is
79+
if (
80+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
81+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
82+
) {
83+
return klass;
84+
}
85+
// Otherwise, register all middleware once
86+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
87+
__facade_register__(middleware);
88+
}
89+
90+
// `extend`ing `klass` here so other RPC methods remain callable
91+
return class extends klass {
92+
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
93+
request,
94+
env,
95+
ctx
96+
) => {
97+
this.env = env;
98+
this.ctx = ctx;
99+
if (super.fetch === undefined) {
100+
throw new Error("Entrypoint class does not define a fetch() function.");
101+
}
102+
return super.fetch(request);
103+
};
104+
105+
#dispatcher: Dispatcher = (type, init) => {
106+
if (type === "scheduled" && super.scheduled !== undefined) {
107+
const controller = new __Facade_ScheduledController__(
108+
Date.now(),
109+
init.cron ?? "",
110+
() => {}
111+
);
112+
return super.scheduled(controller);
113+
}
114+
};
115+
116+
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
117+
return __facade_invoke__(
118+
request,
119+
this.env,
120+
this.ctx,
121+
this.#dispatcher,
122+
this.#fetchDispatcher
123+
);
124+
}
125+
};
126+
}
127+
128+
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
129+
if (typeof ENTRY === "object") {
130+
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
131+
} else if (typeof ENTRY === "function") {
132+
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
133+
}
134+
export default WRAPPED_ENTRY;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function stripCfConnectingIPHeader(input, init) {
2+
const request = new Request(input, init);
3+
request.headers.delete("CF-Connecting-IP");
4+
return request;
5+
}
6+
7+
globalThis.fetch = new Proxy(globalThis.fetch, {
8+
apply(target, thisArg, argArray) {
9+
return Reflect.apply(target, thisArg, [
10+
stripCfConnectingIPHeader.apply(null, argArray),
11+
]);
12+
},
13+
});

0 commit comments

Comments
 (0)