Rewrite not working with external url with the port

Open
#210 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, node.js
Domain
backend

Research direction

Start in serve-handler/src/index.js at toTarget (line 88) and shouldRedirect (line 174), then reproduce the redirects configuration with an external destination containing port 20000. The fix is complete when this redirect no longer throws the path-to-regexp TypeError and forwards to the specified external URL.

Written by the indexing model from the issue text.

Description

Run with configured redirects with the specified port:

"redirects": [
    {
      "source": "/api/endpoint",
      "destination": "http://redirect-url:20000/endpoint"
    }
]

Fails with:

INFO  Gracefully shutting down. Please wait...
/Users/crbx/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/path-to-regexp@2.2.1/node_modules/path-to-regexp/index.js:194
     throw new TypeError('Expected "' + token.name + '" to be ' + (token.repeat ? 'an array' : 'a string'))
           ^

TypeError: Expected "20000" to be a string
   at /Users/user/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/path-to-regexp@2.2.1/node_modules/path-to-regexp/index.js:194:13
   at toTarget (/Users/user/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/serve-handler@6.1.5/node_modules/serve-handler/src/index.js:88:9)
   at shouldRedirect (/Users/user/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/serve-handler@6.1.5/node_modules/serve-handler/src/index.js:174:18)
   at module.exports (/Users/user/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/serve-handler@6.1.5/node_modules/serve-handler/src/index.js:583:19)
   at run (file:///Users/user/Library/pnpm/store/v3/tmp/dlx-35334/node_modules/.pnpm/serve@14.2.3/node_modules/serve/build/main.js:181:13)
   at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Dominant language
JavaScript
Stars
618
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/serve-handler

All issues in vercel/serve-handler

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.