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

refactor: utilize Vercel Build Output API to reimplement API proxy #822

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

aofei
Copy link
Member

@aofei aofei commented Aug 28, 2024

This replaces Vercel Edge Middleware with the Vercel Build Output API1 to reimplement the API proxy, cutting costs (no more invocation-based charges), reducing latency (no middle layer or cold starts), and simplifying the setup, while retaining dynamic configuration via the VERCEL_PROXIED_API_BASE_URL environment variable.

Updates #804

Footnotes

  1. https://vercel.com/docs/build-output-api/v3

This replaces Vercel Edge Middleware with the Vercel Build Output
API[^1] to reimplement the API proxy, cutting costs (no more
invocation-based charges), reducing latency (no middle layer or cold
starts), and simplifying the setup, while retaining dynamic
configuration via the `VERCEL_PROXIED_API_BASE_URL` environment
variable.

Updates goplus#804

[^1]: https://vercel.com/docs/build-output-api/v3

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
@qiniu-ci
Copy link

The PR environment is ready, please check the PR environment

[Attention]: This environment will be automatically cleaned up after a certain period of time., please make sure to test it in time. If you have any questions, please contact the builder team.

Copy link
Collaborator

@nighca nighca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

rewrites: [
{
source: '/api/(.*)',
destination: (env.VERCEL_PROXIED_API_BASE_URL as string) + '/$1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看到这里我还很困惑,回忆了很久为啥我们当初用 middleware 而不是 vercel.json 中的 rewrites 来实现代理...

后来总算想起来是因为 vercel.json 中不好用环境变量?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是因为 vercel.json 中不好用环境变量?

是的,就只是因为这一点才用了 middleware

@aofei aofei merged commit 0448586 into goplus:dev Aug 29, 2024
4 checks passed
@aofei aofei deleted the api-proxy branch August 29, 2024 05:03
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

Successfully merging this pull request may close these issues.

3 participants