Closed gaastonsr closed 4 months ago
I see a slightly different problem. With the following simple script:
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
//
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
// MY_SERVICE: Fetcher;
//
// Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
// MY_QUEUE: Queue;
GITLAB_URL: string;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
let resolveOverride = new URL(env.GITLAB_URL).host;
const req = new Request(request, { cf: { resolveOverride: resolveOverride } });
console.log({ resolveOverride: resolveOverride, url: req.url, headers: req.headers });
return fetch(req);
},
};
I get a 500 error
:
[wrangler:err] Error: Network connection lost.
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (32ms)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (33ms)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (68ms)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (76ms)
[wrangler:inf] GET /favicon.ico 500 Internal Server Error (150ms)
and also a warning:
▲ [WARNING] Failed to get worker definitions TypeError: fetch failed
at fetch (/Users/tkuah/code/router/node_modules/wrangler/wrangler-dist/cli.js:17033:19)
at async getRegisteredWorkers
(/Users/tkuah/code/router/node_modules/wrangler/wrangler-dist/cli.js:127225:22)
at async getBoundRegisteredWorkers
(/Users/tkuah/code/router/node_modules/wrangler/wrangler-dist/cli.js:127244:29) {
cause: SocketError: other side closed
at Socket.onSocketEnd
(/Users/tkuah/code/router/node_modules/wrangler/wrangler-dist/cli.js:7263:27)
at Socket.emit (node:events:531:35)
at Socket.emit (node:domain:488:12)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'UND_ERR_SOCKET',
socket: {
localAddress: '127.0.0.1',
localPort: 55798,
remoteAddress: '127.0.0.1',
remotePort: 6284,
remoteFamily: 'IPv4',
timeout: undefined,
bytesWritten: 356,
bytesRead: 391
}
}
}
Thanks for reporting this! Although we do aim to emulate as much of the Cloudflare network stack as possible with wrangler dev
, if you need additional Cloudflare features outside of Workers to work properly, wrangler dev --remote
should give you the highest-fidelity experience. Could you try that? If that doesn't work, feel free to comment with more details and we can re-open and investigate further.
@kuahyeow That looks like an unrelated issue—could you open a new issue with a reproduction?
Which Cloudflare product(s) does this pertain to?
Workers Runtime, Wrangler core, Miniflare
What version(s) of the tool(s) are you using?
3.28.1 [wrangler]
What version of Node are you using?
18.17
What operating system and version are you using?
Debian Bookworm
Describe the Bug
Observed behavior
I have a worker that uses
resolveOverride: foo.com
to communicate with an alternate origin server. When I run the local servernpx wrangler dev
I expect to be able to simulate that behavior.Attempt 1. If I run
npx wrangler dev
and then I access the server usingbar.com
, then I expect myfetch
call to forward the request to my alternate origin defined inresolveOverride
but it doesn't. I thinkresolveOverride
is being ignored locally.Attempt 2. If I run
npx wrangler dev --host='foo.com'
and then I access the server usingbar.com
then I expect myfetch
call to forward the request tofoo.com
maintaining the originalhost
header. Instead, my request is forwarded tofoo.com
but the host is changed tofoo.com
instead of maintainingbar.com
.Steps to reproduce
Attempt 1:
npx wrangler dev
having afetch
call withresolveOverride
pointing toalternateorigin.com
.resolveOverride
.Attempt 2:
npx wrangler dev --host='alternateorigin.com'
alternateorigin.com
but with the host header changed toalternateorigin.com
.Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response