mirror of
https://github.com/go-shiori/shiori.git
synced 2025-02-22 06:53:22 +08:00
Load file from assets again
This commit is contained in:
parent
ead4264280
commit
0560292540
1 changed files with 22 additions and 27 deletions
49
cmd/serve.go
49
cmd/serve.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"mime"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
fp "path/filepath"
|
fp "path/filepath"
|
||||||
|
@ -82,30 +83,26 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveFiles(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func serveFiles(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
// // Read asset path
|
// Read asset path
|
||||||
// path := r.URL.Path
|
path := r.URL.Path
|
||||||
// if path[0:1] == "/" {
|
if path[0:1] == "/" {
|
||||||
// path = path[1:]
|
path = path[1:]
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Load asset
|
// Load asset
|
||||||
// asset, err := assets.ReadFile(path)
|
asset, err := assets.ReadFile(path)
|
||||||
// checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
// // Set response header content type
|
// Set response header content type
|
||||||
// ext := fp.Ext(path)
|
ext := fp.Ext(path)
|
||||||
// mimeType := mime.TypeByExtension(ext)
|
mimeType := mime.TypeByExtension(ext)
|
||||||
// if mimeType != "" {
|
if mimeType != "" {
|
||||||
// w.Header().Set("Content-Type", mimeType)
|
w.Header().Set("Content-Type", mimeType)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Serve asset
|
// Serve asset
|
||||||
// buffer := bytes.NewBuffer(asset)
|
buffer := bytes.NewBuffer(asset)
|
||||||
// io.Copy(w, buffer)
|
io.Copy(w, buffer)
|
||||||
filepath := r.URL.Path
|
|
||||||
filepath = strings.TrimPrefix(filepath, "/")
|
|
||||||
filepath = fp.Join("view", filepath)
|
|
||||||
http.ServeFile(w, r, filepath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func serveIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
|
@ -116,12 +113,10 @@ func serveIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// asset, _ := assets.ReadFile("index.html")
|
asset, _ := assets.ReadFile("index.html")
|
||||||
// w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
// buffer := bytes.NewBuffer(asset)
|
buffer := bytes.NewBuffer(asset)
|
||||||
// io.Copy(w, buffer)
|
io.Copy(w, buffer)
|
||||||
filepath := fp.Join("view", "index.html")
|
|
||||||
http.ServeFile(w, r, filepath)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue