Remove redirects.json and cleanup server.go
The redirects.json file is not used after conversion to ES6-modules and can be removed. Also, some redirects in server.go are not needed anymore and can be removed too. Change-Id: I793d738a4d51c4a86dc56459a9dccc29ec144ec3
This commit is contained in:
parent
d9aa6b035f
commit
e26ab23646
@ -18,7 +18,6 @@ polygerrit_bundle(
|
||||
),
|
||||
outs = ["polygerrit_ui.zip"],
|
||||
entry_point = "elements/gr-app.html",
|
||||
redirects = "redirects.json",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
@ -1,50 +0,0 @@
|
||||
{
|
||||
"description": "See tools/node_tools/polygerrit_app_preprocessor/redirects.ts",
|
||||
"redirects": [
|
||||
{
|
||||
"from": "/bower_components/ba-linkify",
|
||||
"to": {
|
||||
"npm_module": "ba-linkify"
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components/es6-promise",
|
||||
"to": {
|
||||
"npm_module": "es6-promise"
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components/fetch",
|
||||
"to": {
|
||||
"npm_module": "whatwg-fetch",
|
||||
"files": {
|
||||
"fetch.js": "dist/fetch.umd.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components/moment",
|
||||
"to": {
|
||||
"npm_module": "moment"
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components/webcomponentsjs",
|
||||
"to": {
|
||||
"npm_module": "@webcomponents/webcomponentsjs"
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components/page",
|
||||
"to": {
|
||||
"npm_module": "page"
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": "/bower_components",
|
||||
"to": {
|
||||
"npm_module": "polymer-bridges"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -2,7 +2,7 @@ load("//tools/bzl:genrule2.bzl", "genrule2")
|
||||
load("//tools/node_tools/legacy:index.bzl", "polymer_bundler_tool")
|
||||
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
|
||||
|
||||
def polygerrit_bundle(name, srcs, outs, entry_point, redirects):
|
||||
def polygerrit_bundle(name, srcs, outs, entry_point):
|
||||
"""Build .zip bundle from source code
|
||||
|
||||
Args:
|
||||
@ -10,7 +10,6 @@ def polygerrit_bundle(name, srcs, outs, entry_point, redirects):
|
||||
srcs: source files
|
||||
outs: array with a single item - the output file name
|
||||
entry_point: application entry-point
|
||||
redirects: .json file with redirects
|
||||
"""
|
||||
|
||||
app_name = entry_point.split(".html")[0].split("/").pop() # eg: gr-app
|
||||
|
@ -46,36 +46,6 @@ var (
|
||||
bundledPluginsPattern = regexp.MustCompile("https://cdn.googlesource.com/polygerrit_assets/[0-9.]*")
|
||||
)
|
||||
|
||||
type redirectTarget struct {
|
||||
NpmModule string `json:"npm_module"`
|
||||
Dir string `json:"dir"`
|
||||
Files map[string]string `json:"files"`
|
||||
}
|
||||
|
||||
type redirects struct {
|
||||
From string `json:"from"`
|
||||
To redirectTarget `json:"to"`
|
||||
}
|
||||
|
||||
type redirectsJson struct {
|
||||
Redirects []redirects `json:"redirects"`
|
||||
}
|
||||
|
||||
func readRedirects() []redirects {
|
||||
redirectsFile, err := os.Open("app/redirects.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer redirectsFile.Close()
|
||||
redirectsFileContent, err := ioutil.ReadAll(redirectsFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var result redirectsJson
|
||||
json.Unmarshal([]byte(redirectsFileContent), &result)
|
||||
return result.Redirects
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
@ -89,14 +59,12 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
redirects := readRedirects()
|
||||
|
||||
dirListingMux := http.NewServeMux()
|
||||
dirListingMux.Handle("/styles/", http.StripPrefix("/styles/", http.FileServer(http.Dir("app/styles"))))
|
||||
dirListingMux.Handle("/elements/", http.StripPrefix("/elements/", http.FileServer(http.Dir("app/elements"))))
|
||||
dirListingMux.Handle("/behaviors/", http.StripPrefix("/behaviors/", http.FileServer(http.Dir("app/behaviors"))))
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { handleSrcRequest(redirects, dirListingMux, w, req) })
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { handleSrcRequest(dirListingMux, w, req) })
|
||||
|
||||
http.Handle("/fonts/",
|
||||
addDevHeadersMiddleware(http.FileServer(httpfs.New(zipfs.New(fontsArchive, "fonts")))))
|
||||
@ -136,7 +104,7 @@ func addDevHeaders(writer http.ResponseWriter) {
|
||||
|
||||
}
|
||||
|
||||
func handleSrcRequest(redirects []redirects, dirListingMux *http.ServeMux, writer http.ResponseWriter, originalRequest *http.Request) {
|
||||
func handleSrcRequest(dirListingMux *http.ServeMux, writer http.ResponseWriter, originalRequest *http.Request) {
|
||||
parsedUrl, err := url.Parse(originalRequest.RequestURI)
|
||||
if err != nil {
|
||||
writer.WriteHeader(500)
|
||||
@ -146,10 +114,6 @@ func handleSrcRequest(redirects []redirects, dirListingMux *http.ServeMux, write
|
||||
dirListingMux.ServeHTTP(writer, originalRequest)
|
||||
return
|
||||
}
|
||||
if parsedUrl.Path == "/bower_components/web-component-tester/browser.js" {
|
||||
http.Redirect(writer, originalRequest, "/bower_components/wct-browser-legacy/browser.js", 301)
|
||||
return
|
||||
}
|
||||
|
||||
requestPath := parsedUrl.Path
|
||||
|
||||
@ -186,7 +150,7 @@ func handleSrcRequest(redirects []redirects, dirListingMux *http.ServeMux, write
|
||||
}
|
||||
|
||||
func readFile(originalPath string, redirectedPath string) ([]byte, error) {
|
||||
pathsToTry := []string{"app/modulizer_out" + redirectedPath, "app" + redirectedPath}
|
||||
pathsToTry := []string{"app" + redirectedPath}
|
||||
bowerComponentsSuffix := "/bower_components/"
|
||||
nodeModulesPrefix := "/node_modules/"
|
||||
testComponentsPrefix := "/components/"
|
||||
@ -197,8 +161,6 @@ func readFile(originalPath string, redirectedPath string) ([]byte, error) {
|
||||
}
|
||||
|
||||
if strings.HasPrefix(originalPath, bowerComponentsSuffix) {
|
||||
pathsToTry = append(pathsToTry, "node_modules/wct-browser-legacy/node_modules/"+originalPath[len(bowerComponentsSuffix):])
|
||||
pathsToTry = append(pathsToTry, "node_modules/"+originalPath[len(bowerComponentsSuffix):])
|
||||
pathsToTry = append(pathsToTry, "node_modules/@webcomponents/"+originalPath[len(bowerComponentsSuffix):])
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user