mirror of
https://github.com/go-shiori/shiori.git
synced 2025-02-21 14:33:19 +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"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"html/template"
|
||||
"mime"
|
||||
"io"
|
||||
"net/http"
|
||||
fp "path/filepath"
|
||||
|
@ -82,30 +83,26 @@ func init() {
|
|||
}
|
||||
|
||||
func serveFiles(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
// // Read asset path
|
||||
// path := r.URL.Path
|
||||
// if path[0:1] == "/" {
|
||||
// path = path[1:]
|
||||
// }
|
||||
// Read asset path
|
||||
path := r.URL.Path
|
||||
if path[0:1] == "/" {
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
// // Load asset
|
||||
// asset, err := assets.ReadFile(path)
|
||||
// checkError(err)
|
||||
// Load asset
|
||||
asset, err := assets.ReadFile(path)
|
||||
checkError(err)
|
||||
|
||||
// // Set response header content type
|
||||
// ext := fp.Ext(path)
|
||||
// mimeType := mime.TypeByExtension(ext)
|
||||
// if mimeType != "" {
|
||||
// w.Header().Set("Content-Type", mimeType)
|
||||
// }
|
||||
// Set response header content type
|
||||
ext := fp.Ext(path)
|
||||
mimeType := mime.TypeByExtension(ext)
|
||||
if mimeType != "" {
|
||||
w.Header().Set("Content-Type", mimeType)
|
||||
}
|
||||
|
||||
// // Serve asset
|
||||
// buffer := bytes.NewBuffer(asset)
|
||||
// io.Copy(w, buffer)
|
||||
filepath := r.URL.Path
|
||||
filepath = strings.TrimPrefix(filepath, "/")
|
||||
filepath = fp.Join("view", filepath)
|
||||
http.ServeFile(w, r, filepath)
|
||||
// Serve asset
|
||||
buffer := bytes.NewBuffer(asset)
|
||||
io.Copy(w, buffer)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// asset, _ := assets.ReadFile("index.html")
|
||||
// w.Header().Set("Content-Type", "text/html")
|
||||
// buffer := bytes.NewBuffer(asset)
|
||||
// io.Copy(w, buffer)
|
||||
filepath := fp.Join("view", "index.html")
|
||||
http.ServeFile(w, r, filepath)
|
||||
asset, _ := assets.ReadFile("index.html")
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
buffer := bytes.NewBuffer(asset)
|
||||
io.Copy(w, buffer)
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue