Skip to content

Commit 2687249

Browse files
committed
Fix Angular "bug" whereby anchor tags don't work over slow connections
(by removing Angular)
1 parent 36d6d81 commit 2687249

17 files changed

+105
-1045
lines changed

Gopkg.lock

+32-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

-26
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
2-
# Gopkg.toml example
3-
#
4-
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5-
# for detailed Gopkg.toml documentation.
6-
#
7-
# required = ["github.com/user/thing/cmd/thing"]
8-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9-
#
10-
# [[constraint]]
11-
# name = "github.com/user/project"
12-
# version = "1.0.0"
13-
#
14-
# [[constraint]]
15-
# name = "github.com/user/project2"
16-
# branch = "dev"
17-
# source = "github.com/myfork/project2"
18-
#
19-
# [[override]]
20-
# name = "github.com/x/y"
21-
# version = "2.4.0"
22-
231
[prune]
242
non-go = true
253
go-tests = true
@@ -37,10 +15,6 @@
3715
branch = "master"
3816
name = "github.com/onsi/gomega"
3917

40-
[[constraint]]
41-
branch = "master"
42-
name = "github.com/tedsuo/rata"
43-
4418
[[constraint]]
4519
branch = "master"
4620
name = "github.com/unrolled/secure"

clipr.go

+29-15
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package main
33
import (
44
"fmt"
55
"io/ioutil"
6+
"log"
67
"net/http"
78
"os"
9+
"path/filepath"
810
"sort"
11+
"text/template"
912

1013
"code.cloudfoundry.org/cli-plugin-repo/web"
11-
"github.com/tedsuo/rata"
1214
"github.com/unrolled/secure"
13-
"gopkg.in/yaml.v2"
15+
yaml "gopkg.in/yaml.v2"
1416
)
1517

1618
type CLIPR struct {
@@ -36,18 +38,34 @@ func (cmd *CLIPR) Execute(args []string) error {
3638

3739
sort.Sort(plugins)
3840

39-
handlers := map[string]http.Handler{
40-
Index: http.FileServer(http.Dir("ui")),
41-
List: web.NewListPluginsHandler(plugins, logger),
42-
UI: http.RedirectHandler("/", http.StatusMovedPermanently),
43-
}
44-
45-
router, err := rata.NewRouter(Routes, handlers)
46-
41+
tmpl, err := template.ParseFiles(filepath.Join("ui", "index.html"))
4742
if err != nil {
4843
return err
4944
}
5045

46+
mux := http.NewServeMux()
47+
48+
staticHandler := http.FileServer(http.Dir("ui"))
49+
mux.Handle("/images/", staticHandler)
50+
mux.Handle("/css/", staticHandler)
51+
mux.Handle("/font/", staticHandler)
52+
mux.Handle("/favicon.ico", http.RedirectHandler("/images/favicon.png", http.StatusFound))
53+
mux.Handle("/list", web.NewListPluginsHandler(plugins, logger)) // we no longer use for rendering, but keeping around in case others do
54+
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
55+
if r.URL.Path != "/" {
56+
http.Redirect(w, r, "/", http.StatusMovedPermanently)
57+
return
58+
}
59+
w.Header().Set("Content-Type", "text/html")
60+
err := tmpl.Execute(w, plugins)
61+
if err != nil { // should only error if template has syntax errors
62+
log.Println(err)
63+
}
64+
})
65+
66+
var router http.Handler
67+
router = mux
68+
5169
if cmd.ForceSSL {
5270
secureMiddleware := secure.New(secure.Options{
5371
SSLRedirect: true,
@@ -56,9 +74,5 @@ func (cmd *CLIPR) Execute(args []string) error {
5674
router = secureMiddleware.Handler(router)
5775
}
5876

59-
return http.ListenAndServe(cmd.bindAddr(), router)
60-
}
61-
62-
func (cmd *CLIPR) bindAddr() string {
63-
return fmt.Sprintf(":%d", cmd.Port)
77+
return http.ListenAndServe(fmt.Sprintf(":%d", cmd.Port), router)
6478
}

main_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main_test
22

33
import (
4+
"strings"
5+
46
. "github.com/onsi/ginkgo"
57
. "github.com/onsi/gomega"
68

@@ -47,14 +49,15 @@ var _ = Describe("Integration", func() {
4749
Expect(err).NotTo(HaveOccurred())
4850
Expect(response).To(BeSuccessful())
4951

50-
b, err := ioutil.ReadFile("ui/index.html")
51-
Expect(err).NotTo(HaveOccurred())
52-
5352
defer response.Body.Close()
5453
contents, err := ioutil.ReadAll(response.Body)
5554
Expect(err).NotTo(HaveOccurred())
5655

57-
Expect(string(contents)).To(Equal(string(b)))
56+
// sanity test that at least one thing is present
57+
Expect(strings.Index(string(contents), "doctor scans your deployed applications") >= 0).To(BeTrue())
58+
59+
// and that the template finishes rendering without aborting due to an error
60+
Expect(strings.Index(string(contents), "</html>") >= 0).To(BeTrue())
5861
})
5962
})
6063

routes.go

-20
This file was deleted.

0 commit comments

Comments
 (0)