Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrites Not Working as Expected #121

Open
rajput-hemant opened this issue Sep 9, 2023 · 3 comments
Open

Rewrites Not Working as Expected #121

rajput-hemant opened this issue Sep 9, 2023 · 3 comments

Comments

@rajput-hemant
Copy link

It appears that rewrites are not functioning as expected. Here's my vercel.json configuration:

{
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/api"
    }
  ],
  "functions": {
    "api/**/*.rs": {
      "runtime": "[email protected]"
    }
  }
}

Additionally, when I navigate to an API route, I receive the following error when running vc dev:

❯ vc dev
Vercel CLI 32.2.0
> Ready! Available at http://localhost:3000
> Building [email protected]:api/simple.rs
> Built [email protected]:api/simple.rs [2s]
Error: spawn /home/rajput-hemant/.cache/com.vercel.fun/runtimes/provided/bootstrap EACCES
    at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
Error: An unexpected error occurred!
Error: spawn /home/rajput-hemant/.cache/com.vercel.fun/runtimes/provided/bootstrap EACCES
    at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
@rajput-hemant
Copy link
Author

I managed to rewrite the path with the following vercel.json configuration for example/simple:

{
	"rewrites": [
		{ "source": "/simple", "destination": "/api/simple.rs" },
		{ "source": "/complex", "destination": "/api/complex.rs" },
		{ "source": "/user/:id", "destination": "/api/user/[id].rs" }
	],
	"functions": {
		"api/**/*.rs": {
			"runtime": "[email protected]"
		}
	}
}

However, this doesn't seem to work for the Experimental bundling API. Here is my vercel.json configuration, using the bundled_api macro for example/route-merge:

{
	"rewrites": [{ "source": "/(.*)", "destination": "/api/main.rs" }],
	"functions": {
		"api/main.rs": {
			"runtime": "[email protected]"
		}
	}
}

With this configuration, when I navigate to the route /foo, i.e., without /api as the base path, I get the usual 404: NOT_FOUND, and when I navigate to the route /api/foo, I get 502: BAD_GATEWAY and see this panic log in the terminal:

❯ vc dev
Vercel CLI 32.2.0
> Ready! Available at http://localhost:3000
> Building [email protected]:api/main.rs
> Built [email protected]:api/main.rs [4s]
thread 'main' panicked at 'internal error: entered unreachable code', examples/route-merge/api/main.rs:8:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
TypeError: Object prototype may only be an Object or null: undefined
    at Function.setPrototypeOf (<anonymous>)
    at new LambdaError (/home/rajput-hemant/.bun/install/global/node_modules/vercel/dist/index.js:13136:16)
    at Lambda.<anonymous> (/home/rajput-hemant/.bun/install/global/node_modules/vercel/dist/index.js:13269:27)
    at Generator.next (<anonymous>)
    at fulfilled (/home/rajput-hemant/.bun/install/global/node_modules/vercel/dist/index.js:13183:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

@dglsparsons
Copy link
Collaborator

Hi @rajput-hemant - thanks for raising this. From your examples it looks like we don't support both rewrites and function bundling at the same time. I'll have a look into this though 🙏

@rajput-hemant
Copy link
Author

@dglsparsons Thanks for your quick response and for looking into this. I'm hopeful that this issue can be fixed, as having both rewrites and function bundling would be a valuable addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants