-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffold: support for hosting a React app. (#649)
- Loading branch information
Showing
32 changed files
with
45,881 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assets |
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,71 @@ | ||
package middleware | ||
|
||
import ( | ||
"io/fs" | ||
"net/http" | ||
"path" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type ServeFileSystem interface { | ||
http.FileSystem | ||
Exists(prefix string, path string) bool | ||
} | ||
|
||
type localFileSystem struct { | ||
http.FileSystem | ||
fs fs.FS | ||
root string | ||
indexes bool | ||
} | ||
|
||
func LocalFile(root string, indexes bool, fs fs.FS) *localFileSystem { | ||
return &localFileSystem{ | ||
FileSystem: http.FS(fs), | ||
fs: fs, | ||
root: root, | ||
indexes: indexes, | ||
} | ||
} | ||
|
||
func (l *localFileSystem) Exists(prefix string, filepath string) bool { | ||
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) { | ||
name := path.Join(l.root, p) | ||
|
||
fsFile, err := l.fs.Open(name) | ||
if err != nil { | ||
return false | ||
} | ||
stat, err := fsFile.Stat() | ||
if err != nil { | ||
return false | ||
} | ||
if stat.IsDir() { | ||
if !l.indexes { | ||
index := path.Join(name, "index.html") | ||
_, err := l.fs.Open(index) | ||
if err != nil { | ||
return false | ||
} | ||
} | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// Static returns a middleware handler that serves static files in the given directory. | ||
func Serve(urlPrefix string, fs ServeFileSystem) gin.HandlerFunc { | ||
fileserver := http.FileServer(fs) | ||
if urlPrefix != "" { | ||
fileserver = http.StripPrefix(urlPrefix, fileserver) | ||
} | ||
return func(c *gin.Context) { | ||
if fs.Exists(urlPrefix, c.Request.URL.Path) { | ||
fileserver.ServeHTTP(c.Writer, c.Request) | ||
c.Abort() | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
!flowpipe |
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,3 @@ | ||
# Flowpipe UI | ||
|
||
React App for Flowpipe. |
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,24 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
Oops, something went wrong.