diff --git a/config.go b/config.go index 27cddab..b970d41 100644 --- a/config.go +++ b/config.go @@ -6,14 +6,18 @@ import ( "io/ioutil" ) -type configuration struct { - Host string - Port string - DocRoot string +type configStaticHtml struct { + Dir string StaticUrl string StripPrefix string } +type configuration struct { + Host string + Port string + Static []configStaticHtml +} + var configFile = "config.json" var config = configuration{} diff --git a/config.json b/config.json index cc56ce2..4f4cba0 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,21 @@ { "Host":"localhost", "Port":"8080", - "DocRoot": "./html/", - "StaticUrl": "/spa/", - "StripPrefix" : "/spa/" + "Static": [ + { + "Dir": "./html/", + "StaticUrl": "/", + "StripPrefix" : "/" + }, + { + "Dir": "./html/test/", + "StaticUrl": "/spa1/", + "StripPrefix" : "/spa1/" + }, + { + "Dir": "./html/test/", + "StaticUrl": "/spa2/", + "StripPrefix" : "/spa2/" + } + ] } \ No newline at end of file diff --git a/html/css/index.css b/html/css/index.css index 0c2b980..1a87e13 100644 --- a/html/css/index.css +++ b/html/css/index.css @@ -1,3 +1,24 @@ -H1 { +p { background-color:yellow; +} + +h1 { + text-align: center; + text-decoration: #1ABC9C; +} + +div { + width: 300px; + margin: auto; + text-align: left; +} + +hr { + width: 100px; + border: 10px solid green; + border-radius: 5px; +} + +li{ + padding-bottom:15px; } \ No newline at end of file diff --git a/html/index.html b/html/index.html index faec340..84bdf5f 100644 --- a/html/index.html +++ b/html/index.html @@ -3,7 +3,30 @@ -

this is static file

- test link index.css +

Static Html Site

+
+
+

+ This is a static website located on / +

+ +
    +
  1. + css/index.css +
  2. +
  3. + static url /spa1 → "./html/test/" +
  4. +
  5. + static url /spa2 → "./html/test/" +
  6. +
  7. + static url /test → "./html/test/" +
  8. + +
+
+ + diff --git a/html/test/css/test.css b/html/test/css/test.css new file mode 100644 index 0000000..ec4ec0c --- /dev/null +++ b/html/test/css/test.css @@ -0,0 +1,22 @@ +p { + background-color:lightblue; + padding: 20px 5px; +} + +h1 { + text-align: center; + text-decoration: overline; +} + +div { + width: 300px; + margin: auto; + text-align: left; + background-color: yellow; +} + +hr { + width: 100px; + border: 6px solid lightcoral; + border-radius: 5px; +} \ No newline at end of file diff --git a/html/test/index.html b/html/test/index.html new file mode 100644 index 0000000..af7cdbc --- /dev/null +++ b/html/test/index.html @@ -0,0 +1,30 @@ + + Demo static "Test" + + +

Test

+

+ +
+
+

+ This is a static website located on /test but virtually accessed by /spa1 and /spa2 +

+ +
+ + +

+ +
+ + + diff --git a/main.go b/main.go index cdba140..13b61dc 100644 --- a/main.go +++ b/main.go @@ -23,10 +23,12 @@ func main() { } func setupRootFileServer() { - - fs := http.FileServer(http.Dir(config.DocRoot + "test")) - http.Handle(config.StaticUrl, http.StripPrefix(config.StripPrefix, fs)) - + //root of doc + for idx, node := range config.Static { + log.Printf("setting up %d static with %+v\n", idx, node) + fs := http.FileServer(http.Dir(node.Dir)) + http.Handle(node.StaticUrl, http.StripPrefix(node.StripPrefix, fs)) + } } func setupHTTPHandler() {