Make default React App working

wip
Letzbor Jonas 2022-09-22 15:22:58 +02:00
parent 634d1d6e62
commit 0b72670917
40 changed files with 5545 additions and 29 deletions

8
.gitignore vendored
View File

@ -21,3 +21,11 @@
# Go workspace file
go.work
# Locally used configuration file
/config.yaml
# Vite build file
/.vite
# Log files
*.log

20
BUILD.md 100644
View File

@ -0,0 +1,20 @@
## Projekt anlegen
npm init vite@latest ui -- --template react-ts
cd ui
npm install
cd ..
go get
## Ausführen
set GOTMPDIR=C:\MYCOMP
go run .\cmd\web
npm run dev
npm run build
nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run cmd/MyProgram/main.go

View File

@ -0,0 +1,62 @@
package main
import (
"crypto/tls"
"net/http"
"time"
"rpjosh.de/ncDocConverter/internal/models"
"rpjosh.de/ncDocConverter/pkg/logger"
)
type WebApplication struct {
logger *logger.Logger
config *models.WebConfig
}
func main() {
defer logger.CloseFile()
config, err := models.SetConfig()
if err != nil {
logger.Error(err.Error())
}
tlsConfig := &tls.Config{
CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
},
}
webApp := WebApplication{
logger: logger.GetGlobalLogger(),
config: config,
}
srv := &http.Server{
Addr: config.Server.Address,
ErrorLog: nil,
Handler: webApp.routes(),
TLSConfig: tlsConfig,
IdleTimeout: time.Minute,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
logger.Info("Server started on %s", config.Server.Address)
var errw error
if config.Server.Certificate == "" {
errw = srv.ListenAndServe()
} else {
errw = srv.ListenAndServeTLS(config.Server.Certificate+"cert.pem", config.Server.Certificate+"key.pem")
}
logger.Error("Failed to run the HTTP Server: %s", errw)
}

View File

@ -0,0 +1,68 @@
package main
import (
"fmt"
"net/http"
"runtime/debug"
"github.com/justinas/nosurf"
"rpjosh.de/ncDocConverter/pkg/logger"
)
func secureHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Note: This is split across multiple lines for readability. You don't
// need to do this in your own code.
w.Header().Set("Content-Security-Policy",
//"default-src 'self' localhost:*; style-src 'self' fonts.googleapis.com localhost:*; font-src fonts.gstatic.com")
"default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';")
w.Header().Set("Referrer-Policy", "origin-when-cross-origin")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "deny")
w.Header().Set("X-XSS-Protection", "0")
next.ServeHTTP(w, r)
})
}
func (app *WebApplication) logRequest(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger.Info("%s - %s %s %s", r.RemoteAddr, r.Proto, r.Method, r.URL.RequestURI())
next.ServeHTTP(w, r)
})
}
func (app *WebApplication) recoverPanic(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Create a deferred function (which will always be run in the event
// of a panic as Go unwinds the stack).
defer func() {
// Use the builtin recover function to check if there has been a
// panic or not. If there has...
if err := recover(); err != nil {
// Set a "Connection: close" header on the response.
w.Header().Set("Connection", "close")
// Call the app.serverError helper method to return a 500
// Internal Server response.
trace := fmt.Sprintf("%s\n%s", fmt.Errorf("%s", err).Error(), debug.Stack())
logger.Error(trace)
}
}()
next.ServeHTTP(w, r)
})
}
// Create a NoSurf middleware function which uses a customized CSRF cookie with
// the Secure, Path and HttpOnly attributes set.
func noSurf(next http.Handler) http.Handler {
csrfHandler := nosurf.New(next)
csrfHandler.SetBaseCookie(http.Cookie{
HttpOnly: true,
Path: "/",
Secure: true,
})
return csrfHandler
}

View File

@ -0,0 +1,23 @@
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"rpjosh.de/ncDocConverter/internal/api"
"rpjosh.de/ncDocConverter/internal/frontend"
)
func (app *WebApplication) routes() http.Handler {
frontend := frontend.Frontend{Logger: app.logger, Config: app.config}
api := api.Api{Logger: app.logger, Config: app.config}
router := chi.NewRouter()
router.Use(middleware.RealIP, app.recoverPanic, app.logRequest, secureHeaders)
frontend.SetupServer(router)
api.SetupServer(router)
return router
}

View File

@ -0,0 +1,19 @@
server:
address: ":4000"
# Path to the folder with the certificates file (cert.pem and key.pem) for using TLS
certificate: "/etc/letsencrypt/live/"
# Enables the development server with hot reload function (spans a vite server)
developmentServer: false
# Port on which the development server should listen to
developmentServerPort: 5173
logging:
# Minimum log Level for printing to the console (debug, info, warning, error, fatal)
printLogLevel: info
# Minimum log level for writing into the log file (debug, info, warning, error, fatal)
writeLogLevel: warning
# File path to log (empty = disabled)
logFilePath: "/home/myUser/logs/ncDocConverter.live"

9
go.mod
View File

@ -1,3 +1,12 @@
module rpjosh.de/ncDocConverter
go 1.18
require (
github.com/go-chi/chi/v5 v5.0.7 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
github.com/justinas/nosurf v1.1.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
// https://zhwt.github.io/yaml-to-go/

9
go.sum 100644
View File

@ -0,0 +1,9 @@
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/justinas/nosurf v1.1.1 h1:92Aw44hjSK4MxJeMSyDa7jwuI9GR2J/JCQiaKvXXSlk=
github.com/justinas/nosurf v1.1.1/go.mod h1:ALpWdSbuNGy2lZWtyXdjkYv4edL23oSEgfBT1gPJ5BQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -0,0 +1,17 @@
package api
import (
"github.com/go-chi/chi/v5"
"rpjosh.de/ncDocConverter/internal/models"
"rpjosh.de/ncDocConverter/pkg/logger"
)
type Api struct {
Logger *logger.Logger
Config *models.WebConfig
}
func (api *Api) SetupServer(router *chi.Mux) {
api.routes(router)
}

View File

@ -0,0 +1,7 @@
package api
import "github.com/go-chi/chi/v5"
func (api *Api) routes(router *chi.Mux) {
}

View File

@ -0,0 +1,28 @@
package frontend
import (
"text/template"
"github.com/go-chi/chi/v5"
"rpjosh.de/ncDocConverter/internal/models"
"rpjosh.de/ncDocConverter/pkg/logger"
)
// Contains the shared dependencies needed for the WebApplication
type Frontend struct {
Logger *logger.Logger
Config *models.WebConfig
templateCache map[string]*template.Template
}
func (app *Frontend) SetupServer(router *chi.Mux) {
templateCache, err := newTemplateCache()
if err != nil {
logger.Fatal("Failed to parse the templates", err)
}
app.templateCache = templateCache
app.setServerConfiguration()
app.routes(router)
}

View File

@ -0,0 +1,31 @@
package frontend
import (
"bytes"
"fmt"
"net/http"
)
func (app *Frontend) home(w http.ResponseWriter, r *http.Request) {
app.render(w, http.StatusOK, "main.tmpl.html", app.newTemplateData(r))
}
func (app *Frontend) render(w http.ResponseWriter, status int, page string, data *templateData) {
ts, ok := app.templateCache[page]
if !ok {
err := fmt.Errorf("the template %s does not exist", page)
app.serverError(w, err)
return
}
buf := new(bytes.Buffer)
err := ts.ExecuteTemplate(buf, "base", data)
if err != nil {
app.serverError(w, err)
return
}
w.WriteHeader(status)
buf.WriteTo(w)
}

View File

@ -0,0 +1,32 @@
package frontend
import (
"fmt"
"net/http"
"runtime/debug"
"rpjosh.de/ncDocConverter/pkg/logger"
)
// The serverError helper writes an error message and stack trace to the errorLog,
// then sends a generic 500 Internal Server Error response to the user.
func (app *Frontend) serverError(w http.ResponseWriter, err error) {
trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack())
logger.Error(trace)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
// The clientError helper sends a specific status code and corresponding description
// to the user. We'll use this later in the book to send responses like 400 "Bad
// Request" when there's a problem with the request that the user sent.
func (app *Frontend) clientError(w http.ResponseWriter, status int) {
http.Error(w, http.StatusText(status), status)
}
// For consistency, we'll also implement a notFound helper. This is simply a
// convenience wrapper around clientError which sends a 404 Not Found response to
// the user.
func (app *Frontend) notFound(w http.ResponseWriter) {
app.clientError(w, http.StatusNotFound)
}

View File

@ -0,0 +1,83 @@
package frontend
import (
"fmt"
"io/fs"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/go-chi/chi/v5"
"rpjosh.de/ncDocConverter/pkg/logger"
"rpjosh.de/ncDocConverter/web"
)
func (app *Frontend) routes(router *chi.Mux) {
if app.Config.Server.DevelopmentServer {
app.renderForDev(router)
} else {
app.renderForProd(router)
}
router.Route("/", func(mainRouter chi.Router) {
mainRouter.Get("/", app.home)
})
router.NotFound(func(w http.ResponseWriter, r *http.Request) {
app.notFound(w)
})
}
// Runs the vite Server as an sub process for serving the files with the hot reload function.
// The src directory will also be exposed from within this server for the asserts
func (app *Frontend) renderForDev(router *chi.Mux) {
// serve assets from src folder
FileServer(router, "/src", http.Dir("./web/app/src"))
logger.Info("[DEV] Started vite dev server on http://localhost:%d", app.Config.Server.DevelopmentServerPort)
vite := exec.Command(filepath.Join(".", "node_modules", ".bin", "vite"), "--mode", "development", "--port", fmt.Sprint(app.Config.Server.DevelopmentServerPort))
vite.Dir = "./web/app/"
vite.Stdout = os.Stdout
vite.Stderr = os.Stderr
err := vite.Start()
if err != nil {
logger.Error("Failed to start the vite development server: %s", err)
}
}
// This serves all the needed files from the ebedded file system within the binary
// -> no additional WebServer
func (app *Frontend) renderForProd(router *chi.Mux) {
staticFolder, err := fs.Sub(web.FrontendFiles, "app/dist/assets")
if err != nil {
logger.Fatal("Cannot access the embedded directory 'src'. %s", err)
}
FileServer(router, "/assets", http.FS(staticFolder))
}
func FileServer(r chi.Router, path string, root http.FileSystem) {
if strings.ContainsAny(path, "{}*") {
logger.Info("FileServer does not permit any URL parameters.")
}
if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", http.StatusMovedPermanently).ServeHTTP)
path += "/"
}
path += "*"
r.Get(path, func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/") {
http.NotFound(w, r)
return
}
rctx := chi.RouteContext(r.Context())
pathPrefix := strings.TrimSuffix(rctx.RoutePattern(), "/*")
fs := http.StripPrefix(pathPrefix, http.FileServer(root))
fs.ServeHTTP(w, r)
})
}

View File

@ -0,0 +1,89 @@
package frontend
import (
"fmt"
"io/fs"
"net/http"
"path/filepath"
"text/template"
"rpjosh.de/ncDocConverter/web"
)
type serverConfig struct {
Version string
Development bool
SourceServer string
}
// the server config does never change again -> set this once at startup
var serverConf *serverConfig = &serverConfig{
Version: "1.0.0",
}
type templateData struct {
Version string
ServerConfig *serverConfig
}
// Returns the absolute URL on the WebServer to the given TypeScript file given without the file extension
// main -> http://localhost:4000/assets/main.js
func getJSFile(file string) string {
if serverConf.Development {
return serverConf.SourceServer + "src/" + file + ".tsx"
}
return serverConf.SourceServer + "assets/" + file + ".js"
}
var functions = template.FuncMap{
"getJSFile": getJSFile,
}
func (app *Frontend) setServerConfiguration() {
serverConf.Development = app.Config.Server.DevelopmentServer
sourceServer := ""
if serverConf.Development {
sourceServer = fmt.Sprintf("http://localhost:%d/", app.Config.Server.DevelopmentServerPort)
} else {
sourceServer = fmt.Sprintf("http://localhost%s/", app.Config.Server.Address)
}
serverConf.SourceServer = sourceServer
}
func (app *Frontend) newTemplateData(r *http.Request) *templateData {
return &templateData{
ServerConfig: serverConf,
}
}
// Initializes a new cache containing all templates of the application
// from the embedded file system
func newTemplateCache() (map[string]*template.Template, error) {
cache := map[string]*template.Template{}
pages, err := fs.Glob(&web.TemplateFiles, "template/pages/*.tmpl.html")
if err != nil {
return nil, err
}
for _, page := range pages {
name := filepath.Base(page)
patterns := []string{
"template/base.tmpl.html",
"template/vitejs.tmpl.html",
page,
}
ts, err := template.New(name).Funcs(functions).ParseFS(web.TemplateFiles, patterns...)
if err != nil {
return nil, err
}
cache[name] = ts
}
return cache, nil
}

View File

@ -0,0 +1,95 @@
package models
import (
"flag"
"fmt"
"os"
yaml "gopkg.in/yaml.v3"
"rpjosh.de/ncDocConverter/pkg/logger"
)
type WebConfig struct {
Server Server `yaml:"server"`
Logging Logging `yaml:"logging"`
}
type Server struct {
Address string `yaml:"address"`
Certificate string `yaml:"certificate"`
DevelopmentServer bool `yaml:"developmentServer"`
DevelopmentServerPort int `yaml:"developmentServerPort"`
}
type Logging struct {
PrintLogLevel string `yaml:"printLogLevel"`
WriteLogLevel string `yaml:"writeLogLevel"`
LogFilePath string `yaml:"logFilePath"`
}
func ParseConfig(webConfig *WebConfig, file string) (*WebConfig, error) {
if file == "" {
return webConfig, nil
}
dat, err := os.ReadFile(file)
if err != nil {
return nil, err
}
if err := yaml.Unmarshal(dat, &webConfig); err != nil {
return nil, err
}
return webConfig, nil
}
func getDefaultConfig() *WebConfig {
return &WebConfig{
Server: Server{
Address: ":4000",
DevelopmentServerPort: 5173,
},
Logging: Logging{
PrintLogLevel: "info",
WriteLogLevel: "warning",
},
}
}
// Applies the cli and the configuration options from the config files
func SetConfig() (*WebConfig, error) {
configPath := "./config.yaml"
// the path of the configuration file is needed first to determine the "default" values
for i, arg := range os.Args {
if arg == "-config" || arg == "--config" && len(os.Args) > i {
configPath = os.Args[i+1]
break
}
}
webConfig := getDefaultConfig()
webConfig, err := ParseConfig(webConfig, configPath)
if err != nil {
return nil, fmt.Errorf("unable to parse the configuration file '%s': %s", configPath, err)
}
_ = flag.String("config", "./config.yaml", "Path to the configuration file (see configs/config.yaml) for an example")
address := flag.String("address", webConfig.Server.Address, "Address and port on which the api and the web server should listen to")
printLogLevel := flag.String("printLogLevel", webConfig.Logging.PrintLogLevel, "Minimum log level to log (debug, info, warning, error, fatal)")
devServer := flag.Bool("dev", webConfig.Server.DevelopmentServer, "Enables the development server with hot reload support")
flag.Parse()
webConfig.Server.Address = *address
webConfig.Logging.PrintLogLevel = *printLogLevel
webConfig.Server.DevelopmentServer = *devServer
defaultLogger := logger.Logger{
PrintLevel: logger.GetLevelByName(webConfig.Logging.PrintLogLevel),
LogLevel: logger.GetLevelByName(webConfig.Logging.WriteLogLevel),
LogFilePath: webConfig.Logging.LogFilePath,
PrintSource: true,
}
logger.SetGlobalLogger(&defaultLogger)
return webConfig, err
}

22
main.go
View File

@ -1,22 +0,0 @@
package main
import (
"rpjosh.de/ncDocConverter/logger"
)
func init() {
defaultLogger := logger.Logger {
PrintLevel: 0,
LogLevel: 1,
LogFilePath: "log.log",
PrintSource: true,
}
logger.SetGlobalLogger(&defaultLogger)
}
func main() {
defer logger.CloseFile()
}

View File

@ -10,7 +10,7 @@ import (
"os"
)
// define available log levels
// Level of the log message
type Level uint8
const (
LevelDebug Level = iota
@ -35,7 +35,6 @@ type Logger struct {
var dLogger Logger
func init() {
dLogger = Logger {
PrintLevel: LevelDebug,
LogLevel: LevelInfo,
@ -52,7 +51,7 @@ func (l Logger) Log(level Level, message string, parameters ...any) {
}
func (l Logger) log(level Level, message string, parameters ...any) {
pc, file, line, ok := runtime.Caller(2)
pc, file, line, ok := runtime.Caller(3)
if (!ok) {
file = "#unknown"
line = 0
@ -110,6 +109,7 @@ func getSourceMessage(file string, line int, pc uintptr, l Logger) (string) {
}
func (l *Logger) setup() {
// log.Ldate|log.Ltime|log.Lshortfile
l.consoleLogger = log.New(os.Stdout, "", 0)
l.consoleLoggerErr = log.New(os.Stderr, "", 0)
@ -131,10 +131,10 @@ func (l *Logger) setup() {
}
func (l *Logger) CloseFile() {
if (dLogger.logFile != nil) {
dLogger.logFile.Close()
dLogger.logFile = nil
dLogger.fileLogger = nil
if (l.logFile != nil) {
l.logFile.Close()
l.logFile = nil
l.fileLogger = nil
}
}
@ -143,6 +143,9 @@ func SetGlobalLogger(l *Logger) {
dLogger = *l
dLogger.setup()
}
func GetGlobalLogger() (*Logger) {
return &dLogger
}
func Debug(message string, parameters ...any) {
dLogger.Log(LevelDebug, message, parameters...)
@ -162,4 +165,23 @@ func Fatal(message string, parameters ...any) {
func CloseFile() {
dLogger.CloseFile()
}
// Tries to convert the given level name to the corresponding level code.
// Allowed values are: 'debug', 'info', 'warn', 'warning', 'error', 'panic' and 'fatal'
// If an incorrect level name was given an warning is logged and info will be returned
func GetLevelByName(levelName string) Level {
levelName = strings.ToLower(levelName)
switch (levelName) {
case "debug": return LevelDebug
case "info": return LevelInfo
case "warn", "warning": return LevelWarning
case "error": return LevelError
case "panic", "fatal": return LevelFatal
default: {
Warning("Unable to parse the level name '%s'. Expected 'debug', 'info', 'warn', 'error' or 'fatal'", levelName)
return LevelInfo
}
}
}

14
scripts/run.cmd 100644
View File

@ -0,0 +1,14 @@
@ECHO OFF
:: Bypass the "Terminate Batch Job" prompt
if "%~1"=="-FIXED_CTRL_C" (
:: Remove the -FIXED_CTRL_C parameter
SHIFT
) ELSE (
:: Run the batch with <NUL and -FIXED_CTRL_C
CALL <NUL %0 -FIXED_CTRL_C %*
GOTO :EOF
)
set GOTMPDIR=C:\MYCOMP
nodemon --delay 1s -e go,html --ignore web/app/ --exec go run ./cmd/ncDocConverth --signal SIGTERM

3
scripts/run.sh 100644
View File

@ -0,0 +1,3 @@
#!/bin/sh
nodemon --delay 1s -e go,html --ignore web/app/ --exec go run ./cmd/ncDocConverth --signal SIGTERM

24
web/app/.gitignore vendored 100644
View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

13
web/app/index.html 100644
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

4559
web/app/package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
{
"name": "vite-number-conversion",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"antd": "^4.23.2",
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"nodemon": "^2.0.20",
"typescript": "^4.6.4",
"vite": "^3.1.0"
}
}

View File

@ -0,0 +1,41 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 7em;
padding: 1.5em;
will-change: filter;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}

View File

@ -0,0 +1,36 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from './assets/vite.svg'
import './App.css'
function App() {
const [count, setCount] = useState(0)
const hi: string = "Servus"
return (
<div className="App">
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://reactjs.org" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</div>
)
}
export default App

View File

@ -0,0 +1,3 @@
#HELLOIHRBOYSDA {
background-color: aliceblue;
}

View File

@ -0,0 +1,12 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './Sep.css'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<div id="HELLOIHRBOYSDA">
</div>
</React.StrictMode>
)

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,70 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

View File

@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
)

1
web/app/src/vite-env.d.ts vendored 100644
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

View File

@ -0,0 +1,20 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
},
input: {
main: "src/main.tsx",
sep: "src/Sep.tsx",
},
}
}
})

14
web/efs.go 100644
View File

@ -0,0 +1,14 @@
package web
import (
"embed"
)
//go:embed "app/dist"
var FrontendFiles embed.FS
//go:embed "app/src"
var DevelopeFiles embed.FS
//go:embed "template"
var TemplateFiles embed.FS

View File

@ -0,0 +1,16 @@
{{define "base"}}
<!doctype html>
<html lang='de'>
<head>
<meta charset='utf-8'>
<title>Vite + React + Go</title>
<!-- <base href="http://localhost:5173" > -->
{{if not .ServerConfig.Development}}
<script type="module" src='{{ getJSFile "jsx-runtime"}}'></script>
{{end}}
</head>
<body>
{{template "main" .}}
</body>
</html>
{{end}}

View File

@ -0,0 +1,12 @@
{{define "main"}}
<div id="root"></div>
{{template "vitejs" .}}
<script type="module" src='{{ getJSFile "main"}}'></script>
{{if not .ServerConfig.Development}}
<link rel="stylesheet" href="assets/main.css">
{{end}}
{{end}}

View File

@ -0,0 +1,11 @@
{{define "vitejs"}}
{{if .ServerConfig.Development}}
<script type="module">
import RefreshRuntime from "{{.ServerConfig.SourceServer}}@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
{{end}}
{{end}}