Loads of stuff, check roadmap changes in the README :P
This commit is contained in:
parent
e1fca030bc
commit
68ae33e78a
15 changed files with 17179 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
|||
/server/craban.sqlite
|
||||
/server/web/static/*
|
||||
/webapp/node_modules/
|
||||
/webapp/.parcel-cache/
|
||||
|
|
2
Makefile
2
Makefile
|
@ -9,4 +9,4 @@ mod:
|
|||
|
||||
.PHONY: test
|
||||
test:
|
||||
cd server && go test -v -race ./...
|
||||
cd server && go test -v -race -count 1 ./...
|
||||
|
|
13
README.md
13
README.md
|
@ -8,14 +8,15 @@ Default configuration can be found in the
|
|||
## Roadmap
|
||||
|
||||
- [ ] Add simple logger everywhere
|
||||
- [ ] Make server start, teardown and block
|
||||
- [ ] Bootstrap webapp
|
||||
- [ ] Embed webapp in server
|
||||
- [ ] Split server and webapp in different folders
|
||||
- [ ] Add modd for easy development forkflow
|
||||
- [X] Make server start, teardown and block
|
||||
- [X] Bootstrap webapp
|
||||
- [X] Embed webapp in server
|
||||
- [X] Split server and webapp in different folders
|
||||
- [X] Add modd for easy development forkflow
|
||||
- [ ] Add webapp make targets
|
||||
- [ ] Add bundle and install make targets
|
||||
- [ ] Create basic webapp structure and development workflow
|
||||
- [X] Create basic webapp structure and development workflow
|
||||
- [X] Think of a better name
|
||||
- [ ] Add email config and communications
|
||||
- [ ] Add webpush notifications
|
||||
- [ ] Add webapp linter
|
||||
|
|
16
modd.conf
Normal file
16
modd.conf
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
prep: echo "Starting Craban development environment"
|
||||
}
|
||||
|
||||
webapp/src/** {
|
||||
indir: webapp
|
||||
prep: npm run build
|
||||
prep: ./fix-index-hash.sh
|
||||
}
|
||||
|
||||
server/**/*.go server/web/static/** {
|
||||
indir: server
|
||||
prep: go build ./cmd/craban
|
||||
prep: chmod +x ./craban
|
||||
daemon +sigterm: ./craban
|
||||
}
|
|
@ -24,7 +24,7 @@ func main() {
|
|||
closed := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
fmt.Println("Starting craban")
|
||||
fmt.Println("Starting craban server")
|
||||
if err := srv.Start(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error running server: %s", err)
|
||||
os.Exit(1)
|
||||
|
|
BIN
server/craban
Executable file
BIN
server/craban
Executable file
Binary file not shown.
26
server/web/not_found_redirect.go
Normal file
26
server/web/not_found_redirect.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type NotFoundIndexResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
status int
|
||||
}
|
||||
|
||||
func (nfr *NotFoundIndexResponseWriter) WriteHeader(status int) {
|
||||
nfr.status = status
|
||||
if status != http.StatusNotFound {
|
||||
nfr.ResponseWriter.WriteHeader(status)
|
||||
}
|
||||
}
|
||||
|
||||
func (nfr *NotFoundIndexResponseWriter) Write(p []byte) (int, error) {
|
||||
if nfr.status != http.StatusNotFound {
|
||||
return nfr.ResponseWriter.Write(p)
|
||||
}
|
||||
|
||||
nfr.Header().Add("Content-Type", "text/html; charset=utf-8")
|
||||
return nfr.ResponseWriter.Write(indexBytes)
|
||||
}
|
|
@ -1,10 +1,20 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
var staticFS embed.FS
|
||||
var indexBytes []byte
|
||||
|
||||
func init() {
|
||||
indexBytes, _ = staticFS.ReadFile("static/index.html")
|
||||
}
|
||||
|
||||
type WebServer struct {
|
||||
*http.Server
|
||||
}
|
||||
|
@ -12,9 +22,13 @@ type WebServer struct {
|
|||
func NewWebServer(port int) (*WebServer, error) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// ToDo: configure routes
|
||||
// ToDo: register WS and API endpoints here
|
||||
|
||||
staticFSSub, _ := fs.Sub(staticFS, "static")
|
||||
staticFileServerHandler := http.FileServer(http.FS(staticFSSub))
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello craban!!")
|
||||
srw := &NotFoundIndexResponseWriter{ResponseWriter: w}
|
||||
staticFileServerHandler.ServeHTTP(srw, r)
|
||||
})
|
||||
|
||||
s := &WebServer{
|
||||
|
|
9
webapp/.editorconfig
Normal file
9
webapp/.editorconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
1
webapp/.nvmrc
Normal file
1
webapp/.nvmrc
Normal file
|
@ -0,0 +1 @@
|
|||
v16.9.1
|
7
webapp/fix-index-hash.sh
Executable file
7
webapp/fix-index-hash.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
outputDir="../server/web/static"
|
||||
|
||||
mv $outputDir/index.*.js $outputDir/index.js
|
||||
mv $outputDir/index.*.js.map $outputDir/index.js.map
|
||||
sed -i -E "s/index.\w+.js/index.js/" $outputDir/index.html
|
17055
webapp/package-lock.json
generated
Normal file
17055
webapp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
18
webapp/package.json
Normal file
18
webapp/package.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "craban",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"dev": "parcel src/index.html",
|
||||
"build": "parcel build src/index.html --dist-dir ../server/web/static/ --no-cache",
|
||||
"watch": "parcel watch src/index.html --dist-dir ../server/web/static/ --no-cache"
|
||||
},
|
||||
"author": "Miguel de la Cruz <miguel@mcrx.me>",
|
||||
"devDependencies": {
|
||||
"parcel": "^2.0.0-rc.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
}
|
||||
}
|
12
webapp/src/index.html
Normal file
12
webapp/src/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<title>Craban</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
7
webapp/src/index.js
Normal file
7
webapp/src/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import ReactDOM from 'react-dom'
|
||||
|
||||
const App = () => {
|
||||
return <h1>Hello Craban!!</h1>
|
||||
}
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('app'))
|
Loading…
Reference in a new issue