-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create the new FileServer and HandleDir, deprecate the rest APIBuilde…
…r/Party static methods and more relative: #1283 and removing pongo2 from vendor: https://github.com/kataras/iris/issues/1284
- Loading branch information
Showing
123 changed files
with
1,555 additions
and
9,714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
_examples/file-server/basic/assets/app2/app22/just_a_text_no_index.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
just a text. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello App2App3 index</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello App2 index</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kataras/iris/httptest" | ||
) | ||
|
||
type resource string | ||
|
||
func (r resource) contentType() string { | ||
switch filepath.Ext(r.String()) { | ||
case ".js": | ||
return "application/javascript" | ||
case ".css": | ||
return "text/css" | ||
case ".ico": | ||
return "image/x-icon" | ||
case ".html", "": | ||
return "text/html" | ||
default: | ||
return "text/plain" | ||
} | ||
} | ||
|
||
func (r resource) String() string { | ||
return string(r) | ||
} | ||
|
||
func (r resource) strip(strip string) string { | ||
s := r.String() | ||
return strings.TrimPrefix(s, strip) | ||
} | ||
|
||
func (r resource) loadFromBase(dir string) string { | ||
filename := r.String() | ||
|
||
filename = r.strip("/static") | ||
if filepath.Ext(filename) == "" { | ||
// root /. | ||
filename = filename + "/index.html" | ||
} | ||
|
||
fullpath := filepath.Join(dir, filename) | ||
|
||
b, err := ioutil.ReadFile(fullpath) | ||
if err != nil { | ||
panic(fullpath + " failed with error: " + err.Error()) | ||
} | ||
|
||
result := string(b) | ||
|
||
return result | ||
} | ||
|
||
func TestFileServerBasic(t *testing.T) { | ||
var urls = []resource{ | ||
"/static/css/main.css", | ||
"/static/js/jquery-2.1.1.js", | ||
"/static/favicon.ico", | ||
"/static/app2", | ||
"/static/app2/app2app3", | ||
"/static", | ||
} | ||
|
||
app := newApp() | ||
// route := app.GetRouteReadOnly("GET/{file:path}") | ||
// if route == nil { | ||
// app.Logger().Fatalf("expected a route to serve files") | ||
// } | ||
|
||
// if expected, got := "./assets", route.StaticDir(); expected != got { | ||
// app.Logger().Fatalf("expected route's static directory to be: '%s' but got: '%s'", expected, got) | ||
// } | ||
|
||
// if !route.StaticDirContainsIndex() { | ||
// app.Logger().Fatalf("epxected ./assets to contain an %s file", "/index.html") | ||
// } | ||
|
||
e := httptest.New(t, app) | ||
for _, u := range urls { | ||
url := u.String() | ||
contents := u.loadFromBase("./assets") | ||
|
||
e.GET(url).Expect(). | ||
Status(httptest.StatusOK). | ||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()). | ||
Body().Equal(contents) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.