feat: add /robots.txt (#1355)

* feat: add /robots.txt

* disallow all crawler by default.
This commit is contained in:
oliverch
2019-09-17 05:21:08 +08:00
committed by Aaron Schlesinger
parent 800024fc6f
commit 874d27158d
7 changed files with 36 additions and 0 deletions
+1
View File
@@ -30,6 +30,7 @@ func addProxyRoutes(
r.HandleFunc("/readyz", getReadinessHandler(s)) r.HandleFunc("/readyz", getReadinessHandler(s))
r.HandleFunc("/version", versionHandler) r.HandleFunc("/version", versionHandler)
r.HandleFunc("/catalog", catalogHandler(s)) r.HandleFunc("/catalog", catalogHandler(s))
r.HandleFunc("/robots.txt", robotsHandler(c))
for _, sumdb := range c.SumDBs { for _, sumdb := range c.SumDBs {
sumdbURL, err := url.Parse(sumdb) sumdbURL, err := url.Parse(sumdb)
+14
View File
@@ -0,0 +1,14 @@
package actions
import (
"net/http"
"github.com/gomods/athens/pkg/config"
)
// robotsHandler implements GET baseURL/robots.txt
func robotsHandler(c *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, c.RobotsFile)
}
}
+8
View File
@@ -67,6 +67,14 @@ PprofPort = ":3001"
# that contains the letter `D` (for "Direct Access") in the first line. # that contains the letter `D` (for "Direct Access") in the first line.
FilterFile = "" FilterFile = ""
# The filename for the robots.txt.
# ENV override: ATHENS_ROBOTS_FILE
#
# To provide /robots.txt for net crawler.
# Default disallow all crawler.
# Content details to see https://support.google.com/webmasters/answer/6062608
RobotsFile = "robots.txt"
# Timeout is the timeout for external network calls in seconds # Timeout is the timeout for external network calls in seconds
# This value is used as the default for storage backends if they don't specify timeouts # This value is used as the default for storage backends if they don't specify timeouts
# Defaults to 300 # Defaults to 300
+6
View File
@@ -6,8 +6,12 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999 h1:OR8VhtwhcAI3U48/
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/Azure/azure-pipeline-go v0.1.8 h1:KmVRa8oFMaargVesEuuEoiLCQ4zCCwQ8QX/xg++KS20= github.com/Azure/azure-pipeline-go v0.1.8 h1:KmVRa8oFMaargVesEuuEoiLCQ4zCCwQ8QX/xg++KS20=
github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg= github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg=
github.com/Azure/azure-pipeline-go v0.2.1 h1:OLBdZJ3yvOn2MezlWvbrBMTEUQC72zAftRZOMdj5HYo=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c h1:Y5ueznoCekgCWBytF1Q9lTpZ3tJeX37dQtCcGjMCLYI= github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c h1:Y5ueznoCekgCWBytF1Q9lTpZ3tJeX37dQtCcGjMCLYI=
github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y= github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
github.com/Azure/azure-storage-blob-go v0.7.0 h1:MuueVOYkufCxJw5YZzF842DY2MBsp+hLuh2apKY0mck=
github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895 h1:dmc/C8bpE5VkQn65PNbbyACDC8xw8Hpp/NEurdPmQDQ= github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895 h1:dmc/C8bpE5VkQn65PNbbyACDC8xw8Hpp/NEurdPmQDQ=
@@ -144,6 +148,8 @@ github.com/markbates/hmax v1.0.0 h1:yo2N0gBoCnUMKhV/VRLHomT6Y9wUm+oQQENuWJqCdlM=
github.com/markbates/hmax v1.0.0/go.mod h1:cOkR9dktiESxIMu+65oc/r/bdY4bE8zZw3OLhLx0X2c= github.com/markbates/hmax v1.0.0/go.mod h1:cOkR9dktiESxIMu+65oc/r/bdY4bE8zZw3OLhLx0X2c=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149 h1:HfxbT6/JcvIljmERptWhwa8XzP7H3T+Z2N26gTsaDaA=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
+2
View File
@@ -51,6 +51,7 @@ type Config struct {
DownloadMode mode.Mode `envconfig:"ATHENS_DOWNLOAD_MODE"` DownloadMode mode.Mode `envconfig:"ATHENS_DOWNLOAD_MODE"`
DownloadURL string `envconfig:"ATHENS_DOWNLOAD_URL"` DownloadURL string `envconfig:"ATHENS_DOWNLOAD_URL"`
SingleFlightType string `envconfig:"ATHENS_SINGLE_FLIGHT_TYPE"` SingleFlightType string `envconfig:"ATHENS_SINGLE_FLIGHT_TYPE"`
RobotsFile string `envconfig:"ATHENS_ROBOTS_FILE"`
SingleFlight *SingleFlight SingleFlight *SingleFlight
Storage *StorageConfig Storage *StorageConfig
} }
@@ -96,6 +97,7 @@ func defaultConfig() *Config {
NoSumPatterns: []string{}, NoSumPatterns: []string{},
DownloadMode: "sync", DownloadMode: "sync",
DownloadURL: "", DownloadURL: "",
RobotsFile: "robots.txt",
SingleFlight: &SingleFlight{ SingleFlight: &SingleFlight{
Etcd: &Etcd{"localhost:2379,localhost:22379,localhost:32379"}, Etcd: &Etcd{"localhost:2379,localhost:22379,localhost:32379"},
Redis: &Redis{"127.0.0.1:6379"}, Redis: &Redis{"127.0.0.1:6379"},
+3
View File
@@ -90,6 +90,7 @@ func TestEnvOverrides(t *testing.T) {
HGRCPath: "/test/path/.hgrc", HGRCPath: "/test/path/.hgrc",
Storage: &StorageConfig{}, Storage: &StorageConfig{},
SingleFlight: &SingleFlight{}, SingleFlight: &SingleFlight{},
RobotsFile: "robots.txt",
} }
envVars := getEnvMap(expConf) envVars := getEnvMap(expConf)
@@ -282,6 +283,7 @@ func TestParseExampleConfig(t *testing.T) {
SumDBs: []string{"https://sum.golang.org"}, SumDBs: []string{"https://sum.golang.org"},
NoSumPatterns: []string{}, NoSumPatterns: []string{},
DownloadMode: "sync", DownloadMode: "sync",
RobotsFile: "robots.txt",
} }
absPath, err := filepath.Abs(testConfigFile(t)) absPath, err := filepath.Abs(testConfigFile(t))
@@ -322,6 +324,7 @@ func getEnvMap(config *Config) map[string]string {
envVars["ATHENS_PATH_PREFIX"] = config.PathPrefix envVars["ATHENS_PATH_PREFIX"] = config.PathPrefix
envVars["ATHENS_NETRC_PATH"] = config.NETRCPath envVars["ATHENS_NETRC_PATH"] = config.NETRCPath
envVars["ATHENS_HGRC_PATH"] = config.HGRCPath envVars["ATHENS_HGRC_PATH"] = config.HGRCPath
envVars["ATHENS_ROBOTS_FILE"] = config.RobotsFile
storage := config.Storage storage := config.Storage
if storage != nil { if storage != nil {
+2
View File
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /