mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
version 12.1.5
Former-commit-id: cda69f08955cb0d594e98bf26197ee573cbba4b2
This commit is contained in:
@@ -4,5 +4,5 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/betacraft/yaag v1.0.1-0.20191027021412-565f65e36090
|
||||
github.com/kataras/iris/v12 v12.1.4
|
||||
github.com/kataras/iris/v12 v12.1.5
|
||||
)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
just a text.
|
||||
@@ -0,0 +1 @@
|
||||
<h1>Hello App2App3 index</h1>
|
||||
1
_examples/file-server/subdomain/assets/app2/index.html
Normal file
1
_examples/file-server/subdomain/assets/app2/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Hello App2 index</h1>
|
||||
3
_examples/file-server/subdomain/assets/css/main.css
Normal file
3
_examples/file-server/subdomain/assets/css/main.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
background-color: black;
|
||||
}
|
||||
BIN
_examples/file-server/subdomain/assets/favicon.ico
Normal file
BIN
_examples/file-server/subdomain/assets/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
1
_examples/file-server/subdomain/assets/index.html
Normal file
1
_examples/file-server/subdomain/assets/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Hello index</h1>
|
||||
9190
_examples/file-server/subdomain/assets/js/jquery-2.1.1.js
vendored
Normal file
9190
_examples/file-server/subdomain/assets/js/jquery-2.1.1.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
_examples/file-server/subdomain/hosts
Normal file
2
_examples/file-server/subdomain/hosts
Normal file
@@ -0,0 +1,2 @@
|
||||
127.0.0.1 examle.com
|
||||
127.0.0.1 v1.examle.com
|
||||
29
_examples/file-server/subdomain/main.go
Normal file
29
_examples/file-server/subdomain/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
const (
|
||||
addr = "example.com:80"
|
||||
subdomain = "v1"
|
||||
)
|
||||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.Favicon("./assets/favicon.ico")
|
||||
|
||||
v1 := app.Subdomain(subdomain)
|
||||
v1.HandleDir("/", "./assets", iris.DirOptions{})
|
||||
|
||||
// http://v1.example.com
|
||||
// http://v1.example.com/css/main.css
|
||||
// http://v1.example.com/js/jquery-2.1.1.js
|
||||
// http://v1.example.com/favicon.ico
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := newApp()
|
||||
app.Run(iris.Addr(addr))
|
||||
}
|
||||
81
_examples/file-server/subdomain/main_test.go
Normal file
81
_examples/file-server/subdomain/main_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/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) loadFromBase(dir string) string {
|
||||
filename := r.String()
|
||||
|
||||
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 TestFileServerSubdomainBasic(t *testing.T) {
|
||||
urls := []resource{
|
||||
"/css/main.css",
|
||||
"/js/jquery-2.1.1.js",
|
||||
"/favicon.ico",
|
||||
"/app2",
|
||||
"/app2/app2app3",
|
||||
"/",
|
||||
}
|
||||
|
||||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
host = "http://" + subdomain + "." + host
|
||||
|
||||
for _, u := range urls {
|
||||
url := u.String()
|
||||
contents := u.loadFromBase("./assets")
|
||||
|
||||
e.GET(url).WithURL(host).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||
Body().Equal(contents)
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/googollee/go-socket.io v1.4.3-0.20191109153049-7451e2f8c2e0 // indirect
|
||||
github.com/kataras/iris/v12 v12.1.4
|
||||
github.com/kataras/iris/v12 v12.1.5
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user