integrate frontend into builds, add build tags
This commit is contained in:
parent
685bfbd525
commit
aecc0c7935
|
@ -0,0 +1,4 @@
|
|||
server/dist
|
||||
YetAnotherToDoList
|
||||
YetAnotherToDoList.log
|
||||
YetAnotherToDoList.sqlite3
|
17
INSTALL.md
17
INSTALL.md
|
@ -5,6 +5,11 @@ include_toc: true
|
|||
|
||||
# Install YetAnotherToDoList
|
||||
|
||||
It is recommended to use this behind a proxy (e.g.
|
||||
[Apache/httpd](https://httpd.apache.org/) or [NGINX](https://nginx.org/)) to add
|
||||
TLS and [Gzip](https://www.gnu.org/software/gzip/)/[brotli](https://brotli.org/)
|
||||
compression.
|
||||
|
||||
## Requirements:
|
||||
|
||||
- go 1.21.1 (not tested, but _should_ also work in all versions since 1.16)
|
||||
|
@ -13,7 +18,8 @@ include_toc: true
|
|||
|
||||
## Install via `go install`
|
||||
|
||||
When installing via this method, no commit & version information is provided.
|
||||
When installing via this method, no commit & version information is provided and
|
||||
there will be no frontend.
|
||||
|
||||
```bash
|
||||
go install somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList@latest
|
||||
|
@ -31,6 +37,7 @@ In addition to the [requirements](#requirements), you will need `git`,
|
|||
git clone https://somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList.git
|
||||
cd YetAnotherToDoList
|
||||
go mod tidy # only if you want to edit the GraphQL backend
|
||||
make frontend # omit if you want to run headless
|
||||
make build
|
||||
```
|
||||
|
||||
|
@ -42,6 +49,14 @@ BUILD_FLAGS=<go build flags>
|
|||
RUN_FLAGS=<cli arguments for YetAnotherToDoList>
|
||||
```
|
||||
|
||||
You also pass `build tags` to `BUILD_FLAGS`, e.g.
|
||||
`BUILD_FLAGS="-tags headless,dev"` to disable the frontend and enable
|
||||
`GraphiQL`.
|
||||
|
||||
While there is a `tools` build constraint/tag, building with it has no effect.
|
||||
The `tools` package only exists to install the dependencies for the
|
||||
`gqlgen generate` command when you run `go mod tidy`.
|
||||
|
||||
## Install from pre-build binary
|
||||
|
||||
There are currently no pre-build binaries available
|
||||
|
|
4
Makefile
4
Makefile
|
@ -51,6 +51,10 @@ run:
|
|||
|
||||
$(project): build
|
||||
|
||||
.PHONY: frontend
|
||||
frontend:
|
||||
cd frontend && pnpm run build
|
||||
|
||||
.PHONY: install
|
||||
install: $(project)
|
||||
install $(project) $(INSTALL_DIR)
|
||||
|
|
|
@ -3,5 +3,15 @@ import vue from '@vitejs/plugin-vue'
|
|||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
port: 4243,
|
||||
proxy: {
|
||||
'^/(api|playground|version)': 'http://localhost:4242/'
|
||||
}
|
||||
},
|
||||
build: {
|
||||
outDir: '../server/dist',
|
||||
emptyOutDir: true
|
||||
}
|
||||
})
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//go:build dev
|
||||
// +build dev
|
||||
|
||||
/*
|
||||
YetAnotherToDoList
|
||||
Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql/playground"
|
||||
)
|
||||
|
||||
func handleDevTools() {
|
||||
http.Handle("/playground", playground.Handler("GraphQL playground", "/api"))
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//go:build !dev
|
||||
// +build !dev
|
||||
|
||||
/*
|
||||
YetAnotherToDoList
|
||||
Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server
|
||||
|
||||
func handleDevTools() {
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
//go:build !headless
|
||||
// +build !headless
|
||||
|
||||
/*
|
||||
YetAnotherToDoList
|
||||
Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed dist/*
|
||||
var frontend embed.FS
|
||||
|
||||
func handleFrontend() {
|
||||
stripped, err := fs.Sub(frontend, "dist")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
frontendFS := http.FileServer(http.FS(stripped))
|
||||
http.Handle("/", frontendFS)
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//go:build headless
|
||||
// +build headless
|
||||
|
||||
/*
|
||||
YetAnotherToDoList
|
||||
Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server
|
||||
|
||||
func handleFrontend() {
|
||||
}
|
|
@ -22,19 +22,19 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/99designs/gqlgen/graphql/playground"
|
||||
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals"
|
||||
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/graph"
|
||||
)
|
||||
|
||||
func StartServer(port int) {
|
||||
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
|
||||
handleDevTools() // controlled by 'dev' tag
|
||||
handleFrontend() // controlled by 'headless' tag
|
||||
|
||||
http.Handle("/", playground.Handler("GraphQL playground", "/api"))
|
||||
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s %s", globals.Version, globals.CommitHash)
|
||||
})
|
||||
|
||||
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
|
||||
http.Handle("/api", srv)
|
||||
globals.Logger.Printf("connect to http://localhost:%v/ for GraphQL playground", port)
|
||||
globals.Logger.Fatal(http.ListenAndServe(":"+strconv.FormatInt(int64(port), 10), nil))
|
||||
|
|
Loading…
Reference in New Issue