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
40d25f7d
Unverified
Commit
40d25f7d
authored
Jan 12, 2023
by
boojack
Committed by
GitHub
Jan 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: skip api error for static middleware (#941)
parent
1441a1df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
common.go
server/common.go
+5
-0
embed_frontend.go
server/embed_frontend.go
+4
-3
server.go
server/server.go
+1
-4
No files found.
server/common.go
View file @
40d25f7d
...
@@ -22,6 +22,11 @@ func DefaultGetRequestSkipper(c echo.Context) bool {
...
@@ -22,6 +22,11 @@ func DefaultGetRequestSkipper(c echo.Context) bool {
return
c
.
Request
()
.
Method
==
http
.
MethodGet
return
c
.
Request
()
.
Method
==
http
.
MethodGet
}
}
func
DefaultAPIRequestSkipper
(
c
echo
.
Context
)
bool
{
path
:=
c
.
Path
()
return
common
.
HasPrefixes
(
path
,
"/api"
)
}
func
(
server
*
Server
)
DefaultAuthSkipper
(
c
echo
.
Context
)
bool
{
func
(
server
*
Server
)
DefaultAuthSkipper
(
c
echo
.
Context
)
bool
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
path
:=
c
.
Path
()
path
:=
c
.
Path
()
...
...
server/embed_frontend.go
View file @
40d25f7d
...
@@ -25,18 +25,19 @@ func embedFrontend(e *echo.Echo) {
...
@@ -25,18 +25,19 @@ func embedFrontend(e *echo.Echo) {
// Use echo static middleware to serve the built dist folder
// Use echo static middleware to serve the built dist folder
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
Skipper
:
DefaultAPIRequestSkipper
,
HTML5
:
true
,
HTML5
:
true
,
Filesystem
:
getFileSystem
(
"dist"
),
Filesystem
:
getFileSystem
(
"dist"
),
}))
}))
g
:=
e
.
Group
(
"assets"
)
assetsGroup
:=
e
.
Group
(
"assets"
)
g
.
Use
(
func
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
assetsGroup
.
Use
(
func
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
return
func
(
c
echo
.
Context
)
error
{
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderCacheControl
,
"max-age=31536000, immutable"
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderCacheControl
,
"max-age=31536000, immutable"
)
return
next
(
c
)
return
next
(
c
)
}
}
})
})
g
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
assetsGroup
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
HTML5
:
true
,
HTML5
:
true
,
Filesystem
:
getFileSystem
(
"dist/assets"
),
Filesystem
:
getFileSystem
(
"dist/assets"
),
}))
}))
...
...
server/server.go
View file @
40d25f7d
...
@@ -56,9 +56,7 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
...
@@ -56,9 +56,7 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
e
.
Use
(
middleware
.
Gzip
())
e
.
Use
(
middleware
.
Gzip
())
e
.
Use
(
middleware
.
CSRFWithConfig
(
middleware
.
CSRFConfig
{
e
.
Use
(
middleware
.
CSRFWithConfig
(
middleware
.
CSRFConfig
{
Skipper
:
func
(
c
echo
.
Context
)
bool
{
Skipper
:
s
.
DefaultAuthSkipper
,
return
s
.
DefaultAuthSkipper
(
c
)
},
TokenLookup
:
"cookie:_csrf"
,
TokenLookup
:
"cookie:_csrf"
,
}))
}))
...
@@ -73,7 +71,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
...
@@ -73,7 +71,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
}))
}))
e
.
Use
(
middleware
.
TimeoutWithConfig
(
middleware
.
TimeoutConfig
{
e
.
Use
(
middleware
.
TimeoutWithConfig
(
middleware
.
TimeoutConfig
{
Skipper
:
middleware
.
DefaultSkipper
,
ErrorMessage
:
"Request timeout"
,
ErrorMessage
:
"Request timeout"
,
Timeout
:
30
*
time
.
Second
,
Timeout
:
30
*
time
.
Second
,
}))
}))
...
...
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