Cannot POST to worker service

My worker A (using Hono) has GET and POST endpoint like so:
app.get('/test', (c) => {
return c.text('GET /test')
})

app.post('/test', (c) => {
return c.text('POST /test')
})
app.get('/test', (c) => {
return c.text('GET /test')
})

app.post('/test', (c) => {
return c.text('POST /test')
})
In my worker B the code below successfully connect to worker A:
app.get('/test', async (c) => {
return await c.env.WORKER_A.fetch(c.req) // 'GET /test'
})
app.get('/test', async (c) => {
return await c.env.WORKER_A.fetch(c.req) // 'GET /test'
})
But when B tries to talk to A using POST:
app.post('/test', async (c) => {
return await c.env.WORKER_A.fetch(c.req)
})
app.post('/test', async (c) => {
return await c.env.WORKER_A.fetch(c.req)
})
it always error:
Trace: TypeError: Cannot construct a Request with a Request object that has already been used.
at new Request (/Users/polt/aces-workers/auth-test/node_modules/undici/lib/fetch/request.js:488:15)
at new Request (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/core/src/standards/http.ts:393:13)
at upgradingFetch (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/web-sockets/src/fetch.ts:21:19)
at WebSocketPlugin.<anonymous> (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/core/src/standards/http.ts:891:21)
[TRUNCATED}
Trace: TypeError: Cannot construct a Request with a Request object that has already been used.
at new Request (/Users/polt/aces-workers/auth-test/node_modules/undici/lib/fetch/request.js:488:15)
at new Request (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/core/src/standards/http.ts:393:13)
at upgradingFetch (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/web-sockets/src/fetch.ts:21:19)
at WebSocketPlugin.<anonymous> (/Users/polt/aces-workers/auth-test/node_modules/@miniflare/core/src/standards/http.ts:891:21)
[TRUNCATED}
3 Replies
kian
kian2y ago
Are you doing wrangler dev?
muslax
muslaxOP2y ago
Yes, wrangler dev. Ty, will try.
sakuta
sakuta2y ago
c.req is not the raw request object you need to make a fetch request using a Request object here, and not hono's modified/parsed one @muslax that shouldn't be the issue here if you take a look at the error message
Want results from more Discord servers?
Add your server