Skip to content

Throw unexpected error #249

@wqcstrong

Description

@wqcstrong

I've been using the Router from itty-router in a Cloudflare Worker, and I've encountered some unexpected behavior during its usage. The simplified logic of the code is to return the content of https://example.com upon receiving a user request.

// Without using itty-router
export default {
  async fetch(request) {
    return await fetch('https://example.com');
  }
}

When testing in the local development environment using curl, I received the normal HTML content from example.com:

curl http://localhost:8787/

After introducing itty-router:

import { Router, cors, error, json, text, withParams } from 'itty-router';

const { preflight, corsify } = cors({
	origin: /.*/,
	credentials: true,
});

const router = Router({
	before: [preflight, withParams],
	catch: error,
	finally: [corsify, json],
});

router.all('/test', () => {
  return await fetch('https://example.com');
})

export default {
  ...router
}

Continuing the test with curl http://localhost:8787/test, I received the following response:

{"status":500,"error":"Can't modify immutable headers."}%

Could someone please explain what might be causing this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions