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
68413a53
Commit
68413a53
authored
Dec 23, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update frontend service
parent
638f17a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
24 deletions
+10
-24
go.mod
go.mod
+0
-4
go.sum
go.sum
+0
-5
frontend.go
server/frontend/frontend.go
+9
-8
server.go
server/server.go
+1
-7
No files found.
go.mod
View file @
68413a53
...
@@ -23,7 +23,6 @@ require (
...
@@ -23,7 +23,6 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.8.4
github.com/swaggo/echo-swagger v1.4.1
github.com/swaggo/swag v1.16.2
github.com/swaggo/swag v1.16.2
go.uber.org/zap v1.26.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.17.0
...
@@ -43,7 +42,6 @@ require (
...
@@ -43,7 +42,6 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
...
@@ -60,12 +58,10 @@ require (
...
@@ -60,12 +58,10 @@ require (
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
...
...
go.sum
View file @
68413a53
...
@@ -162,7 +162,6 @@ github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
...
@@ -162,7 +162,6 @@ github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
...
@@ -549,10 +548,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
...
@@ -549,10 +548,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/swaggo/echo-swagger v1.4.1 h1:Yf0uPaJWp1uRtDloZALyLnvdBeoEL5Kc7DtnjzO/TUk=
github.com/swaggo/echo-swagger v1.4.1/go.mod h1:C8bSi+9yH2FLZsnhqMZLIZddpUxZdBYuNHbtaS1Hljc=
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=
github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04=
github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04=
github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E=
github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
...
...
server/frontend/frontend.go
View file @
68413a53
...
@@ -35,17 +35,18 @@ func (s *FrontendService) Serve(e *echo.Echo) {
...
@@ -35,17 +35,18 @@ func (s *FrontendService) Serve(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
{
Root
:
"dist"
,
HTML5
:
true
,
Skipper
:
defaultAPIRequestSkipper
,
Filesystem
:
http
.
Dir
(
"dist"
),
HTML5
:
true
,
Skipper
:
func
(
c
echo
.
Context
)
bool
{
return
util
.
HasPrefixes
(
c
.
Path
(),
"/api"
,
"/memos.api.v2"
,
"/robots.txt"
,
"/sitemap.xml"
,
"/m/:memoID"
)
},
}))
}))
s
.
registerRoutes
(
e
)
s
.
registerRoutes
(
e
)
}
}
func
(
s
*
FrontendService
)
registerRoutes
(
e
*
echo
.
Echo
)
{
func
(
s
*
FrontendService
)
registerRoutes
(
e
*
echo
.
Echo
)
{
rawIndexHTMLBytes
,
_
:=
os
.
ReadFile
(
"dist/index.html"
)
rawIndexHTML
:=
getRawIndexHTML
()
rawIndexHTML
:=
string
(
rawIndexHTMLBytes
)
e
.
GET
(
"/robots.txt"
,
func
(
c
echo
.
Context
)
error
{
e
.
GET
(
"/robots.txt"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
...
@@ -173,7 +174,7 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) string {
...
@@ -173,7 +174,7 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) string {
return
strings
.
Join
(
metadataList
,
"
\n
"
)
return
strings
.
Join
(
metadataList
,
"
\n
"
)
}
}
func
defaultAPIRequestSkipper
(
c
echo
.
Context
)
bool
{
func
getRawIndexHTML
()
string
{
path
:=
c
.
Request
()
.
URL
.
Path
bytes
,
_
:=
os
.
ReadFile
(
"dist/index.html"
)
return
util
.
HasPrefixes
(
path
,
"/api"
,
"/memos.api.v2"
)
return
string
(
bytes
)
}
}
server/server.go
View file @
68413a53
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/echo/v4/middleware"
"github.com/pkg/errors"
"github.com/pkg/errors"
echoSwagger
"github.com/swaggo/echo-swagger"
apiv1
"github.com/usememos/memos/api/v1"
apiv1
"github.com/usememos/memos/api/v1"
apiv2
"github.com/usememos/memos/api/v2"
apiv2
"github.com/usememos/memos/api/v2"
...
@@ -74,15 +73,10 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
...
@@ -74,15 +73,10 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
}
}
s
.
ID
=
serverID
s
.
ID
=
serverID
//
Serve frontend
.
//
Register frontend service
.
frontendService
:=
frontend
.
NewFrontendService
(
profile
,
store
)
frontendService
:=
frontend
.
NewFrontendService
(
profile
,
store
)
frontendService
.
Serve
(
e
)
frontendService
.
Serve
(
e
)
// Serve swagger in dev/demo mode.
if
profile
.
Mode
==
"dev"
||
profile
.
Mode
==
"demo"
{
e
.
GET
(
"/api/*"
,
echoSwagger
.
WrapHandler
)
}
secret
:=
"usememos"
secret
:=
"usememos"
if
profile
.
Mode
==
"prod"
{
if
profile
.
Mode
==
"prod"
{
secret
,
err
=
s
.
getSystemSecretSessionName
(
ctx
)
secret
,
err
=
s
.
getSystemSecretSessionName
(
ctx
)
...
...
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