Skip to content

Commit

Permalink
refactor: serve basic files
Browse files Browse the repository at this point in the history
  • Loading branch information
aofei committed Aug 13, 2019
1 parent 915c0fc commit 0619834
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
Binary file added apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon.ico
Binary file not shown.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ module github.com/goproxy/goproxy.cn

require (
github.com/BurntSushi/toml v0.3.1
github.com/air-gases/cacheman v0.7.4
github.com/air-gases/defibrillator v0.12.4
github.com/air-gases/limiter v0.12.4
github.com/air-gases/logger v0.12.4
github.com/air-gases/redirector v0.12.4
github.com/aofei/air v0.12.4
github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796
github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6
github.com/mitchellh/mapstructure v1.1.2
github.com/rs/zerolog v1.14.3
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII
github.com/VictoriaMetrics/fastcache v1.5.1 h1:qHgHjyoNFV7jgucU8QZUuU4gcdhfs8QW1kw68OD2Lag=
github.com/VictoriaMetrics/fastcache v1.5.1/go.mod h1:+jv9Ckb+za/P1ZRg/sulP5Ni1v49daAVERr0H3CuscE=
github.com/a8m/mark v0.1.1-0.20170507133748-44f2db618845/go.mod h1:c8Mh99Cw82nrsAnPgxQSZHkswVOJF7/MqZb1ZdvriLM=
github.com/air-gases/cacheman v0.7.4 h1:YHPAHhTqM35p5e2wqmmPvOI8cH2qOrpd8vLJk10J2Wo=
github.com/air-gases/cacheman v0.7.4/go.mod h1:TJmesy/aTLt4S/pobyCsoL3YQxH2yqdnMolO+WNqmSU=
github.com/air-gases/defibrillator v0.12.4 h1:HF0f2sRiUgMjo/Zis7Qk5QGqWxQanqyZvMzorx/Ptfg=
github.com/air-gases/defibrillator v0.12.4/go.mod h1:aE/1W3C8pHIrA5UnCDOZc8GymWzmIMkM+GNauLIGDa4=
github.com/air-gases/limiter v0.12.4 h1:8fbuWeEbCw7Ge4NEu/JGJuSdDJu5i1r+BjSRR1KQNNg=
Expand Down Expand Up @@ -42,8 +44,8 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796 h1:W+BJrnBAHlS2vKFBnEOWM3Qa+qgLDdfMaDHollJgc1A=
github.com/goproxy/goproxy v0.0.0-20190809144859-080f99010796/go.mod h1:rfiiqmbdu8wueRXcp96RTer4wRcBb23lUtdNghyaOas=
github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6 h1:XnIh7jsnREGCHoDsiZnC8JEwrxoad72ATvimcW5B9QA=
github.com/goproxy/goproxy v0.0.0-20190812143559-921935e9a7e6/go.mod h1:rfiiqmbdu8wueRXcp96RTer4wRcBb23lUtdNghyaOas=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
Expand Down
27 changes: 20 additions & 7 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ package handler
import (
"net/http"

"github.com/air-gases/cacheman"
"github.com/aofei/air"
"github.com/goproxy/goproxy"
"github.com/goproxy/goproxy.cn/cfg"
"github.com/goproxy/goproxy/cacher"
)

// a is the `air.Default`.
var a = air.Default
var (
// a is the `air.Default`.
a = air.Default

// getHeadMethods is an array contains the GET and the HEAD methods.
getHeadMethods = []string{http.MethodGet, http.MethodHead}

// cachemanGas is used to manage the Cache-Control header.
cachemanGas = cacheman.Gas(cacheman.GasConfig{
Public: true,
MaxAge: 3600,
SMaxAge: -1,
})
)

func init() {
g := goproxy.New()
Expand All @@ -24,11 +37,11 @@ func init() {

g.ErrorLogger = a.ErrorLogger

a.BATCH(
[]string{http.MethodGet, http.MethodHead},
"/",
indexPageHandler,
)
a.FILE("/robots.txt", "robots.txt")
a.FILE("/favicon.ico", "favicon.ico", cachemanGas)
a.FILE("/apple-touch-icon.png", "apple-touch-icon.png", cachemanGas)
a.FILES("/assets", a.CofferAssetRoot, cachemanGas)
a.BATCH(getHeadMethods, "/", indexPageHandler, cachemanGas)
a.BATCH(nil, "/*", air.WrapHTTPHandler(g))
}

Expand Down
7 changes: 7 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
User-Agent: *
Disallow: /*/@latest
Disallow: /*/@v/list
Disallow: /*/@v/*.info
Disallow: /*/@v/*.mod
Disallow: /*/@v/*.zip
Disallow: /sumdb/

0 comments on commit 0619834

Please sign in to comment.