소스 검색

added static test for directory sub-dir support

master
sp 4 년 전
부모
커밋
2cd53da5f0
7개의 변경된 파일130개의 추가작업 그리고 14개의 파일을 삭제
  1. +8
    -4
      config.go
  2. +17
    -3
      config.json
  3. +22
    -1
      html/css/index.css
  4. +25
    -2
      html/index.html
  5. +22
    -0
      html/test/css/test.css
  6. +30
    -0
      html/test/index.html
  7. +6
    -4
      main.go

+ 8
- 4
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{}


+ 17
- 3
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/"
}
]
}

+ 22
- 1
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;
}

+ 25
- 2
html/index.html 파일 보기

@@ -3,7 +3,30 @@
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<h1> this is static file </h1>
<a href="css/index.css"> test link index.css </a>
<h1> Static Html Site </h1>
<hr>
<div class="center">
<p >
This is a static website located on /
</p>

<ol>
<li>
<a href="css/index.css"> css/index.css </a>
</li>
<li>
static url <a href="spa1/"> /spa1 </a> &#x2192; "./html/test/"
</li>
<li>
static url <a href="spa2/">/spa2 </a> &#x2192; "./html/test/"
</li>
<li>
static url <a href="test/">/test </a> &#x2192; "./html/test/"
</li>

</ol>
</div>


</body>


+ 22
- 0
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;
}

+ 30
- 0
html/test/index.html 파일 보기

@@ -0,0 +1,30 @@
<head>
<title>Demo static "Test" </title>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<h1> Test </h1>
<h1> &#8595; </h1>

<hr>
<div class="center">
<p >
This is a static website located on /test but virtually accessed by /spa1 and /spa2
</p>

<hr>

<ul>
<li>
<a href="css/test.css"> css/test.css </a>
</li>
</ul>
<h1> &#8595; </h1>
<ul>
<li>
<a href="/"> back to "/" &#x2192; "./html/" </a>
</li>
</ul>
</div>




+ 6
- 4
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() {

Loading…
취소
저장