Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
1b50ab5d
Commit
1b50ab5d
authored
Jul 15, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: use echo static middleware to serve dist
parent
6053df05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
32 deletions
+5
-32
.gitignore
.gitignore
+0
-19
embed_frontend.go
server/embed_frontend.go
+5
-13
No files found.
.gitignore
View file @
1b50ab5d
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Temp output
*.out
*.log
tmp
# Air (hot reload) generated
# Air (hot reload) generated
.air
.air
# Frontend asset
# Frontend asset
web/dist
web/dist
# Dev database
data
# build folder
# build folder
build
memos-build
memos-build
.DS_Store
.DS_Store
\ No newline at end of file
server/embed_frontend.go
View file @
1b50ab5d
...
@@ -6,14 +6,12 @@ import (
...
@@ -6,14 +6,12 @@ import (
"net/http"
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
)
//go:embed dist
//go:embed dist
var
embeddedFiles
embed
.
FS
var
embeddedFiles
embed
.
FS
//go:embed dist/index.html
var
indexContent
string
func
getFileSystem
()
http
.
FileSystem
{
func
getFileSystem
()
http
.
FileSystem
{
fs
,
err
:=
fs
.
Sub
(
embeddedFiles
,
"dist"
)
fs
,
err
:=
fs
.
Sub
(
embeddedFiles
,
"dist"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -24,14 +22,8 @@ func getFileSystem() http.FileSystem {
...
@@ -24,14 +22,8 @@ func getFileSystem() http.FileSystem {
}
}
func
embedFrontend
(
e
*
echo
.
Echo
)
{
func
embedFrontend
(
e
*
echo
.
Echo
)
{
// Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
// See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually
HTML5
:
true
,
e
.
GET
(
"/*"
,
func
(
c
echo
.
Context
)
error
{
Filesystem
:
getFileSystem
(),
return
c
.
HTML
(
http
.
StatusOK
,
indexContent
)
}))
})
assetHandler
:=
http
.
FileServer
(
getFileSystem
())
e
.
GET
(
"/assets/*"
,
echo
.
WrapHandler
(
assetHandler
))
e
.
GET
(
"/icons/*"
,
echo
.
WrapHandler
(
assetHandler
))
e
.
GET
(
"/favicon.svg"
,
echo
.
WrapHandler
(
assetHandler
))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment