Localise all external resources so that application can be used without requiring clearnet connectivity
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Add gzip handler so that assets can be compressed if clients request it Add cache-control headers so that content can be effectively cached locally
This commit is contained in:
parent
547e7fdc04
commit
c6a608061e
3
StaticRoot/axios.min.js
vendored
Normal file
3
StaticRoot/axios.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
StaticRoot/bootstrap.bundle.min.js
vendored
Normal file
7
StaticRoot/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
StaticRoot/bootstrap.min.css
vendored
2
StaticRoot/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
BIN
StaticRoot/favicon.png
Normal file
BIN
StaticRoot/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
@ -4,8 +4,9 @@
|
|||||||
<title>DN42 Registry Explorer</title>
|
<title>DN42 Registry Explorer</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<link rel="stylesheet" href="bootstrap.min.css">
|
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
<link rel="stylesheet" href="bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" href="material-icons.css"/>
|
||||||
<!-- Style overrides -->
|
<!-- Style overrides -->
|
||||||
<style>
|
<style>
|
||||||
.material-icons { display:inline-flex;vertical-align:middle }
|
.material-icons { display:inline-flex;vertical-align:middle }
|
||||||
@ -205,13 +206,12 @@ body { box-shadow: inset 0 2em 10em rgba(0,0,0,0.4); min-height: 100vh }
|
|||||||
</span>
|
</span>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
<script src="jquery.slim.min.js"></script>
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
|
<script src="bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://unpkg.com/vue"></script -->
|
<script src="vue.min.js"></script>
|
||||||
<script src="https://unpkg.com/vue-router"></script -->
|
<script src="vue-router.min.js"></script>
|
||||||
<script src="https://unpkg.com/axios@0.18.0/dist/axios.min.js"></script>
|
<script src="axios.min.js"></script>
|
||||||
<!-- script src="https://unpkg.com/vue@2.6.2/dist/vue.min.js"></script -->
|
<script src="anchorme.min.js"></script>
|
||||||
<!-- script src="https://unpkg.com/vue-router@3.0.2/dist/vue-router.js"></script -->
|
|
||||||
<script src="anchorme.min.js"></script>
|
<script src="anchorme.min.js"></script>
|
||||||
<script src="explorer.js"></script>
|
<script src="explorer.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
2
StaticRoot/jquery.slim.min.js
vendored
Normal file
2
StaticRoot/jquery.slim.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
20
StaticRoot/material-icons.css
Normal file
20
StaticRoot/material-icons.css
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'Material Icons';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: url(/material-icons.ttf) format('truetype');
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-icons {
|
||||||
|
font-family: 'Material Icons';
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 24px;
|
||||||
|
line-height: 1;
|
||||||
|
letter-spacing: normal;
|
||||||
|
text-transform: none;
|
||||||
|
display: inline-block;
|
||||||
|
white-space: nowrap;
|
||||||
|
word-wrap: normal;
|
||||||
|
direction: ltr;
|
||||||
|
}
|
BIN
StaticRoot/material-icons.ttf
Normal file
BIN
StaticRoot/material-icons.ttf
Normal file
Binary file not shown.
6
StaticRoot/source-sans-pro.css
Normal file
6
StaticRoot/source-sans-pro.css
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'Source Sans Pro';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 400;
|
||||||
|
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(source-sans-pro.ttf) format('truetype');
|
||||||
|
}
|
BIN
StaticRoot/source-sans-pro.ttf
Normal file
BIN
StaticRoot/source-sans-pro.ttf
Normal file
Binary file not shown.
6
StaticRoot/vue-router.min.js
vendored
Normal file
6
StaticRoot/vue-router.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
6
StaticRoot/vue.min.js
vendored
Normal file
6
StaticRoot/vue.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -9,6 +9,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
@ -143,8 +144,9 @@ func main() {
|
|||||||
|
|
||||||
// initialise router
|
// initialise router
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
// log all access
|
// global handers, log all requests and allow compression
|
||||||
router.Use(requestLogger)
|
router.Use(requestLogger)
|
||||||
|
router.Use(handlers.CompressHandler)
|
||||||
|
|
||||||
// add API routes
|
// add API routes
|
||||||
subr := router.PathPrefix("/api").Subrouter()
|
subr := router.PathPrefix("/api").Subrouter()
|
||||||
|
@ -89,6 +89,9 @@ func dnsRZoneHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
format = []string{"json"}
|
format = []string{"json"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
|
||||||
switch format[0] {
|
switch format[0] {
|
||||||
case "bind":
|
case "bind":
|
||||||
DNSRootZone.WriteBindFormat(w)
|
DNSRootZone.WriteBindFormat(w)
|
||||||
|
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module burble.dn42/dn42regsrv
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/gorilla/handlers v1.5.1
|
||||||
github.com/gorilla/mux v1.7.4
|
github.com/gorilla/mux v1.7.4
|
||||||
github.com/sirupsen/logrus v1.6.0
|
github.com/sirupsen/logrus v1.6.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
4
go.sum
4
go.sum
@ -1,4 +1,8 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
|
||||||
|
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
|
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
|
||||||
|
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
|
||||||
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
|
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
|
||||||
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
27
regapi.go
27
regapi.go
@ -63,6 +63,8 @@ func regMetaHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
Commit: RegistryData.Commit,
|
Commit: RegistryData.Commit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't cache
|
||||||
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
ResponseJSON(w, rv)
|
ResponseJSON(w, rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,6 +313,11 @@ func regRootHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
for _, rType := range RegistryData.Types {
|
for _, rType := range RegistryData.Types {
|
||||||
response[rType.Ref] = len(rType.Objects)
|
response[rType.Ref] = len(rType.Objects)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, response)
|
ResponseJSON(w, response)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -344,6 +351,10 @@ func regTypeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
response[rtype.Ref] = objects
|
response[rtype.Ref] = objects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, response)
|
ResponseJSON(w, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,6 +420,10 @@ func regObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, response)
|
ResponseJSON(w, response)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -427,6 +442,10 @@ func regObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, response)
|
ResponseJSON(w, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,6 +497,10 @@ func regKeyHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, amap)
|
ResponseJSON(w, amap)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,6 +551,10 @@ func regAttributeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a day, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", RegistryData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, amap)
|
ResponseJSON(w, amap)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
roaapi.go
12
roaapi.go
@ -130,6 +130,10 @@ func roaFilterHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
filters = fselect(filters, 6)
|
filters = fselect(filters, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a week, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=604800, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", ROAData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, filters)
|
ResponseJSON(w, filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +151,10 @@ func roaJSONHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
ROAJSONResponse.MetaData.Valid += (ROA_JSON_VALIDITY_PERIOD * 3600)
|
ROAJSONResponse.MetaData.Valid += (ROA_JSON_VALIDITY_PERIOD * 3600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache for up to a week, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=604800, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", ROAData.Commit)
|
||||||
|
|
||||||
ResponseJSON(w, ROAJSONResponse)
|
ResponseJSON(w, ROAJSONResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +182,10 @@ func roaBirdHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
|
// cache for up to a week, but set etag to commit to catch changes
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=604800, stale-if-error=86400")
|
||||||
|
w.Header().Set("ETag", ROAData.Commit)
|
||||||
|
|
||||||
fmt.Fprintf(w, "#\n# dn42regsrv ROA Generator\n# Last Updated: %s\n"+
|
fmt.Fprintf(w, "#\n# dn42regsrv ROA Generator\n# Last Updated: %s\n"+
|
||||||
"# Commit: %s\n#\n", ROAData.CTime.String(), ROAData.Commit)
|
"# Commit: %s\n#\n", ROAData.CTime.String(), ROAData.Commit)
|
||||||
|
|
||||||
|
16
static.go
16
static.go
@ -42,8 +42,7 @@ func InstallStaticRoutes(router *mux.Router, staticPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// install a file server for the static route
|
// install a file server for the static route
|
||||||
router.PathPrefix("/").Handler(http.StripPrefix("/",
|
router.PathPrefix("/").Handler(staticHandler(staticPath))
|
||||||
http.FileServer(http.Dir(staticPath)))).Methods("GET")
|
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"path": staticPath,
|
"path": staticPath,
|
||||||
@ -51,5 +50,18 @@ func InstallStaticRoutes(router *mux.Router, staticPath string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
func staticHandler(path string) http.Handler {
|
||||||
|
|
||||||
|
server := http.FileServer(http.Dir(path))
|
||||||
|
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// allow up to a month of caching
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=2592000, stale-if-error=86400")
|
||||||
|
server.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// end of code
|
// end of code
|
||||||
|
Loading…
x
Reference in New Issue
Block a user