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
46d7ecca
Commit
46d7ecca
authored
Jul 10, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use go embed
parent
48d8c6ee
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
66 additions
and
9 deletions
+66
-9
.gitignore
.gitignore
+1
-1
Dockerfile
Dockerfile
+1
-1
index.html
server/dist/index.html
+13
-0
embed_frontend.go
server/embed_frontend.go
+37
-0
server.go
server/server.go
+1
-6
index.html
web/index.html
+1
-1
package.json
web/package.json
+1
-0
favicon.svg
web/public/favicon.svg
+0
-0
vite.config.ts
web/vite.config.ts
+6
-0
yarn.lock
web/yarn.lock
+5
-0
No files found.
.gitignore
View file @
46d7ecca
...
@@ -17,7 +17,7 @@ tmp
...
@@ -17,7 +17,7 @@ tmp
.air
.air
# Frontend asset
# Frontend asset
dist
web/
dist
# Dev database
# Dev database
data
data
...
...
Dockerfile
View file @
46d7ecca
...
@@ -15,6 +15,7 @@ RUN apk update
...
@@ -15,6 +15,7 @@ RUN apk update
RUN
apk
--no-cache
add gcc musl-dev
RUN
apk
--no-cache
add gcc musl-dev
COPY
. .
COPY
. .
COPY
--from=frontend /frontend-build/dist ./server/dist
RUN
go build
\
RUN
go build
\
-o
memos
\
-o
memos
\
...
@@ -25,7 +26,6 @@ FROM alpine:3.16.0 AS monolithic
...
@@ -25,7 +26,6 @@ FROM alpine:3.16.0 AS monolithic
WORKDIR
/usr/local/memos
WORKDIR
/usr/local/memos
COPY
--from=backend /backend-build/memos /usr/local/memos/
COPY
--from=backend /backend-build/memos /usr/local/memos/
COPY
--from=frontend /frontend-build/dist /usr/local/memos/web/dist
# Directory to store the data, which can be referenced as the mounting point.
# Directory to store the data, which can be referenced as the mounting point.
RUN
mkdir
-p
/var/opt/memos
RUN
mkdir
-p
/var/opt/memos
...
...
server/dist/index.html
0 → 100644
View file @
46d7ecca
<!-- THIS FILE IS A PLACEHOLDER AND SHOULD NOT BE CHANGED -->
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
/>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
<title>
Memos
</title>
</head>
<body>
<p>
No frontend embeded.
</p>
</body>
</html>
server/embed_frontend.go
0 → 100644
View file @
46d7ecca
package
server
import
(
"embed"
"io/fs"
"net/http"
"github.com/labstack/echo/v4"
)
//go:embed dist
var
embeddedFiles
embed
.
FS
//go:embed dist/index.html
var
indexContent
string
func
getFileSystem
()
http
.
FileSystem
{
fs
,
err
:=
fs
.
Sub
(
embeddedFiles
,
"dist"
)
if
err
!=
nil
{
panic
(
err
)
}
return
http
.
FS
(
fs
)
}
func
embedFrontend
(
e
*
echo
.
Echo
)
{
// Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.
// See https://stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writing-manually
e
.
GET
(
"/*"
,
func
(
c
echo
.
Context
)
error
{
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
))
}
server/server.go
View file @
46d7ecca
...
@@ -38,12 +38,7 @@ func NewServer(profile *profile.Profile) *Server {
...
@@ -38,12 +38,7 @@ func NewServer(profile *profile.Profile) *Server {
Timeout
:
30
*
time
.
Second
,
Timeout
:
30
*
time
.
Second
,
}))
}))
e
.
Use
(
middleware
.
StaticWithConfig
(
middleware
.
StaticConfig
{
embedFrontend
(
e
)
Skipper
:
middleware
.
DefaultSkipper
,
Root
:
"web/dist"
,
Browse
:
true
,
HTML5
:
true
,
}))
// In dev mode, set the const secret key to make signin session persistence.
// In dev mode, set the const secret key to make signin session persistence.
secret
:=
[]
byte
(
"usememos"
)
secret
:=
[]
byte
(
"usememos"
)
...
...
web/index.html
View file @
46d7ecca
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<html
lang=
"en"
>
<html
lang=
"en"
>
<head>
<head>
<meta
charset=
"UTF-8"
/>
<meta
charset=
"UTF-8"
/>
<link
rel=
"icon"
href=
"/
logo
.svg"
sizes=
"64x64"
type=
"image/*"
/>
<link
rel=
"icon"
href=
"/
favicon
.svg"
sizes=
"64x64"
type=
"image/*"
/>
<meta
name=
"theme-color"
content=
"#f6f5f4"
/>
<meta
name=
"theme-color"
content=
"#f6f5f4"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<title>
Memos
</title>
<title>
Memos
</title>
...
...
web/package.json
View file @
46d7ecca
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@types/lodash-es"
:
"^4.17.5"
,
"@types/lodash-es"
:
"^4.17.5"
,
"@types/node"
:
"^18.0.3"
,
"@types/qs"
:
"^6.9.7"
,
"@types/qs"
:
"^6.9.7"
,
"@types/react"
:
"^18.0.9"
,
"@types/react"
:
"^18.0.9"
,
"@types/react-dom"
:
"^18.0.4"
,
"@types/react-dom"
:
"^18.0.4"
,
...
...
web/public/
logo
.svg
→
web/public/
favicon
.svg
View file @
46d7ecca
File moved
web/vite.config.ts
View file @
46d7ecca
import
{
defineConfig
}
from
"vite"
;
import
{
defineConfig
}
from
"vite"
;
import
react
from
"@vitejs/plugin-react"
;
import
react
from
"@vitejs/plugin-react"
;
import
{
resolve
}
from
"path"
;
// https://vitejs.dev/config/
// https://vitejs.dev/config/
export
default
defineConfig
({
export
default
defineConfig
({
...
@@ -17,4 +18,9 @@ export default defineConfig({
...
@@ -17,4 +18,9 @@ export default defineConfig({
},
},
},
},
},
},
resolve
:
{
alias
:
{
"@/"
:
`
${
resolve
(
__dirname
,
"src"
)}
/`
,
},
},
});
});
web/yarn.lock
View file @
46d7ecca
...
@@ -374,6 +374,11 @@
...
@@ -374,6 +374,11 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==
integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==
"@types/node@^18.0.3":
version "18.0.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.3.tgz#463fc47f13ec0688a33aec75d078a0541a447199"
integrity sha512-HzNRZtp4eepNitP+BD6k2L6DROIDG4Q0fm4x+dwfsr6LGmROENnok75VGw40628xf+iR24WeMFcHuuBDUAzzsQ==
"@types/prop-types@*":
"@types/prop-types@*":
version "15.7.5"
version "15.7.5"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
...
...
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