Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Never let two instances serve the same repository or share a data directory: ind

`fly.toml` deploys one Source Graph Machine in `sin`, with 1 GB memory, auto-stop disabled, and a volume named `sourcegraph_data`. The starter volume should be at least 20 GB. Index memory and disk needs depend on repository size; observe real indexing before changing capacity. Do not scale this App to multiple Machines: Machines of one App would share repositories. For sharding, deploy one App per shard behind a routing access layer.

The portal is a separate App. For a unified domain it reverse-proxies the entire `/sourcegraph/` prefix, preserving query strings, cookies and authorization. Keep the configured external origin fixed; never trust arbitrary forwarded hosts. The portal must not cache auth/API/MCP responses. Static assets may be cached independently.
The portal is a separate App. For a unified domain it reverse-proxies the entire `/sourcegraph/` prefix, preserving query strings, cookies and authorization. Keep the configured external origin fixed; never trust arbitrary forwarded hosts. The portal must not cache auth/API/MCP responses. Static assets may be cached independently. The portal forwards the client address as a single `X-Forwarded-For` hop (from Fly's `Fly-Client-IP`); `SOURCEGRAPH_TRUSTED_PROXIES` (comma-separated CIDRs, `fdaa::/16` in `fly.toml`) tells Source Graph to trust it, so anonymous limits and the query error log see each client.

The service answers `/robots.txt` and `/sourcegraph/robots.txt`: crawlers may read the landing pages, not code views, search results, repository pages or the APIs. A portal on the same domain should serve the same rules at its own `/robots.txt`.

```sh
fly apps create context4ai-sourcegraph
Expand Down
14 changes: 14 additions & 0 deletions internal/httpserver/robots.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package httpserver

// RobotsTxt keeps crawlers to the landing pages: code views, search results
// and the APIs they call are per-commit and endless for a crawler.
const RobotsTxt = `User-agent: *
Disallow: /sourcegraph/code
Disallow: /sourcegraph/?
Disallow: /sourcegraph/v1/
Disallow: /sourcegraph/api/
Disallow: /sourcegraph/auth/
Disallow: /sourcegraph/mcp
Disallow: /sourcegraph/repo?
Allow: /
`
20 changes: 20 additions & 0 deletions internal/httpserver/robots_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package httpserver

import (
"net/http/httptest"
"strings"
"testing"
)

// robots.txt is public at the host root and under the prefix.
func TestRobotsTxt(t *testing.T) {
admin := hexID("admin")[:24]
s := newSite(t, map[string]string{"admin": admin}, admin)
for _, path := range []string{"/robots.txt", "/sourcegraph/robots.txt"} {
w := httptest.NewRecorder()
s.handler.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
if w.Code != 200 || !strings.Contains(w.Body.String(), "Disallow: /sourcegraph/code") || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/plain") {
t.Fatalf("%s: %d %q", path, w.Code, w.Body.String())
}
}
}
6 changes: 6 additions & 0 deletions internal/httpserver/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ func runtime(c config.Config, log *slog.Logger, s *service.Service, token string
browserAuth.ServeHTTP(w, r)
return
}
if (r.URL.Path == "/robots.txt" || r.URL.Path == Prefix+"/robots.txt") && (r.Method == "GET" || r.Method == "HEAD") {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("Cache-Control", "public, max-age=86400")
_, _ = io.WriteString(w, RobotsTxt)
return
}
if r.URL.Path == Prefix+"/healthz" {
fallback.ServeHTTP(w, r)
return
Expand Down