#Cannot POST to worker service

9 messages · Page 1 of 1 (latest)

versed dagger
#

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')
})

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'
})

But when B tries to talk to A using POST:

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}
north notch
#

Are you doing wrangler dev?

gilded oar
#

Can you try wrangler@beta - should be fixed

#

and yeah this is wrangler dev

versed dagger
#

Yes, wrangler dev.

versed dagger
restive crane
#

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

#

@versed dagger