-
-
Notifications
You must be signed in to change notification settings - Fork 2k
vercel.json #1695
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
base: main
Are you sure you want to change the base?
vercel.json #1695
Conversation
WalkthroughAdds a Vercel deployment configuration file for a Go app, specifying build/runtime settings and a catch-all route directing all requests to main.go. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant V as Vercel Edge
participant G as main.go (Go Runtime)
rect rgba(200,220,255,0.3)
note over V: New routing config (catch-all)
U->>V: HTTP request to /
V->>G: Forward request to /main.go
G-->>V: Response
V-->>U: HTTP response
end
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
vercel.json (2)
3-8
: Consider using the api/ directory (file‑based functions) instead of legacy builds.Vercel’s Go functions conventionally live under api/*.go. That avoids custom routing to a root-level file and aligns with platform defaults.
If you choose to follow the convention, move main.go to api/index.go and simplify routes:
"builds": [ - { - "src": "main.go", - "use": "@vercel/go" - } + { "src": "api/**/*.go", "use": "@vercel/go" } ], - "routes": [ - { "src": "/(.*)", "dest": "/main.go" } - ] + "routes": [ + { "handle": "filesystem" }, + { "src": "/(.*)", "dest": "/api/index.go" } + ]I can also propose a version that drops "builds" entirely and relies on auto-detection if desired.
2-2
: Keep “version”: 2 but note it’s the legacy schema; prefer rewrites/redirects/headers blocks where possible.No change required now, but if you expand config (redirects, headers), consider the newer “rewrites/redirects/headers” keys for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
vercel.json
(1 hunks)
"src": "main.go", | ||
"use": "@vercel/go" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify handler shape and Go runtime expectations.
Ensure main.go exposes a Vercel-compatible handler (and uses package main). Mismatch here results in 500s at runtime.
Run this to sanity-check the PR branch:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Confirm file exists at expected path
test -f main.go || { echo "main.go not found at repo root"; exit 1; }
# 2) Check it’s a main package
rg -nP '^\s*package\s+main\b' main.go || { echo "package main not declared"; exit 1; }
# 3) Look for an http handler signature commonly used with Vercel Go runtimes
rg -nP '\bfunc\s+(Handler|Handle|handler)\s*\(\s*w\s+http\.ResponseWriter\s*,\s*r\s+\*http\.Request\s*\)' main.go || {
echo "No obvious http handler function found (Handler/Handle/handler)"; exit 1;
}
echo "Basic checks passed."
Length of output: 354
Add missing Vercel-compatible HTTP handler in main.go
main.go declares package main
but lacks an exported function matching Vercel’s Go runtime entrypoint (func Handler(w http.ResponseWriter, r *http.Request)
). Add this handler signature (or update vercel.json to point at your custom entry) to avoid 500 errors at runtime.
🤖 Prompt for AI Agents
In vercel.json around lines 5 to 6, Vercel is configured to use the Go runtime
but main.go currently lacks the exported HTTP entrypoint expected by that
runtime; add an exported function with the exact signature func Handler(w
http.ResponseWriter, r *http.Request) in main.go that forwards to your existing
router/logic (or alternatively update vercel.json to reference a custom
entrypoint if you intend a different export), ensure the package is main and the
function is exported so Vercel can invoke it, and wire any context/response
handling to return appropriate status and body to avoid 500s.
"src": "/(.*)", | ||
"dest": "/main.go" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Catch‑all route can shadow static assets and may self-match; add filesystem handle and exclude the function path.
As written, every request (including to /main.go) routes to /main.go. This can 1) bypass any static files you might add later and 2) ambiguously self-match the function path. Safer to handle existing files first and exclude the function file from the catch-all.
Apply:
"routes": [
- {
- "src": "/(.*)",
- "dest": "/main.go"
- }
+ { "handle": "filesystem" },
+ {
+ "src": "/(?!main\\.go$)(.*)",
+ "dest": "/main.go"
+ }
]
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"src": "/(.*)", | |
"dest": "/main.go" | |
} | |
] | |
"routes": [ | |
{ "handle": "filesystem" }, | |
{ | |
"src": "/(?!main\\.go$)(.*)", | |
"dest": "/main.go" | |
} | |
] |
🤖 Prompt for AI Agents
In vercel.json around lines 11 to 14, the catch‑all route currently matches
every request (including /main.go) which can shadow static assets and
self‑match; add a filesystem handle entry before the catch‑all and change the
catch‑all src to exclude the function file (e.g. use a negative lookahead for
main.go) so existing files are served first and requests to /main.go aren’t
routed into the function.
Summary by CodeRabbit