mirror of
https://github.com/Kugelschieber/migo.git
synced 2026-01-18 06:40:29 +00:00
Basic Vue setup.
This commit is contained in:
48
cmd/admin/.eslintrc.cjs
Normal file
48
cmd/admin/.eslintrc.cjs
Normal file
@@ -0,0 +1,48 @@
|
||||
/* eslint-env node */
|
||||
require('@rushstack/eslint-patch/modern-module-resolution')
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
node: true
|
||||
},
|
||||
'extends': [
|
||||
'plugin:vue/vue3-essential',
|
||||
'eslint:recommended',
|
||||
'@vue/eslint-config-typescript'
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2021
|
||||
},
|
||||
rules: {
|
||||
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
||||
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
|
||||
"vue/multi-word-component-names": "off",
|
||||
"indent": "off",
|
||||
"vue/html-indent": ["warn", 4, {
|
||||
"alignAttributesVertically": false
|
||||
}],
|
||||
"vue/script-indent": ["warn", 4, {
|
||||
"baseIndent": 1,
|
||||
"switchCase": 1
|
||||
}],
|
||||
"vue/mustache-interpolation-spacing": ["error", "never"],
|
||||
"vue/v-on-style": ["error", "longform"],
|
||||
"vue/max-attributes-per-line": ["warn", {
|
||||
singleline: {
|
||||
max: 99
|
||||
}
|
||||
}],
|
||||
"vue/singleline-html-element-content-newline": "off",
|
||||
"vue/attributes-order": "off",
|
||||
"vue/first-attribute-linebreak": "off",
|
||||
"vue/attribute-hyphenation": "off",
|
||||
"vue/html-closing-bracket-newline": "off",
|
||||
"vue/v-slot-style": "off",
|
||||
"vue/no-v-html": "off",
|
||||
"vue/html-self-closing": "off",
|
||||
"vue/require-default-prop": "off"
|
||||
}
|
||||
}
|
||||
28
cmd/admin/.gitignore
vendored
Normal file
28
cmd/admin/.gitignore
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
1
cmd/admin/env.d.ts
vendored
Normal file
1
cmd/admin/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -1 +1,13 @@
|
||||
<h1>Admin</h1>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Migo Admin</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
4012
cmd/admin/package-lock.json
generated
Normal file
4012
cmd/admin/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
cmd/admin/package.json
Normal file
33
cmd/admin/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "migo",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite build --watch",
|
||||
"build": "run-p type-check build-only",
|
||||
"preview": "vite preview",
|
||||
"build-only": "vite build",
|
||||
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
||||
},
|
||||
"dependencies": {
|
||||
"pinia": "^2.1.3",
|
||||
"sass": "^1.63.6",
|
||||
"vue": "^3.3.4",
|
||||
"vue-router": "^4.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rushstack/eslint-patch": "^1.2.0",
|
||||
"@tsconfig/node18": "^2.0.1",
|
||||
"@types/node": "^18.16.17",
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"@vue/tsconfig": "^0.4.0",
|
||||
"eslint": "^8.39.0",
|
||||
"eslint-plugin-vue": "^9.11.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"typescript": "~5.0.4",
|
||||
"vite": "^4.3.9",
|
||||
"vue-tsc": "^1.6.5"
|
||||
}
|
||||
}
|
||||
BIN
cmd/admin/public/favicon.ico
Normal file
BIN
cmd/admin/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
13
cmd/admin/src/App.vue
Normal file
13
cmd/admin/src/App.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from "vue";
|
||||
|
||||
export default defineComponent({});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import "@/assets/main.scss";
|
||||
</style>
|
||||
4
cmd/admin/src/assets/main.scss
Normal file
4
cmd/admin/src/assets/main.scss
Normal file
@@ -0,0 +1,4 @@
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
9
cmd/admin/src/main.ts
Normal file
9
cmd/admin/src/main.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
|
||||
createApp(App)
|
||||
.use(createPinia())
|
||||
.use(router)
|
||||
.mount("#app");
|
||||
15
cmd/admin/src/router/index.ts
Normal file
15
cmd/admin/src/router/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {createRouter, createWebHistory} from "vue-router";
|
||||
import SignIn from "../views/SignIn.vue";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: SignIn
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
export default router;
|
||||
5
cmd/admin/src/stores/counter.ts
Normal file
5
cmd/admin/src/stores/counter.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import {defineStore} from "pinia";
|
||||
|
||||
export const useCounterStore = defineStore("counter", () => {
|
||||
return {}
|
||||
})
|
||||
9
cmd/admin/src/views/SignIn.vue
Normal file
9
cmd/admin/src/views/SignIn.vue
Normal file
@@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<h1>Sign In</h1>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {defineComponent} from "vue";
|
||||
|
||||
export default defineComponent({});
|
||||
</script>
|
||||
12
cmd/admin/tsconfig.app.json
Normal file
12
cmd/admin/tsconfig.app.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
|
||||
"exclude": ["src/**/__tests__/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
11
cmd/admin/tsconfig.json
Normal file
11
cmd/admin/tsconfig.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
cmd/admin/tsconfig.node.json
Normal file
15
cmd/admin/tsconfig.node.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@tsconfig/node18/tsconfig.json",
|
||||
"include": [
|
||||
"vite.config.*",
|
||||
"vitest.config.*",
|
||||
"cypress.config.*",
|
||||
"nightwatch.conf.*",
|
||||
"playwright.config.*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "ESNext",
|
||||
"types": ["node"]
|
||||
}
|
||||
}
|
||||
20
cmd/admin/vite.config.ts
Normal file
20
cmd/admin/vite.config.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
base: "/admin",
|
||||
define: {
|
||||
__VITE_PROD_DEVTOOLS__: false
|
||||
}
|
||||
})
|
||||
86
cmd/main.go
86
cmd/main.go
@@ -1,16 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"github.com/Kugelschieber/migo/db"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed admin
|
||||
admin embed.FS
|
||||
//go:embed admin/dist/index.html
|
||||
index []byte
|
||||
|
||||
//go:embed admin/dist/favicon.ico
|
||||
favicon []byte
|
||||
|
||||
//go:embed admin/dist/assets
|
||||
assets embed.FS
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -19,14 +31,80 @@ func main() {
|
||||
}
|
||||
|
||||
defer db.Close()
|
||||
dev := os.Getenv("MIGO_DEV") != ""
|
||||
router := chi.NewRouter()
|
||||
router.Handle("/admin/*", http.FileServer(http.FS(admin)))
|
||||
router.Use(middleware.Compress(5))
|
||||
router.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: []string{"https://*", "http://*"},
|
||||
AllowedMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodOptions},
|
||||
AllowedHeaders: []string{"*"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 86400,
|
||||
}))
|
||||
router.Handle("/admin", http.RedirectHandler("/admin/", http.StatusFound))
|
||||
router.Route("/admin/", func(r chi.Router) {
|
||||
if dev {
|
||||
r.Handle("/assets/*", http.StripPrefix("/admin/assets/", http.FileServer(http.Dir("cmd/admin/dist/assets"))))
|
||||
r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "cmd/admin/dist/favicon.ico")
|
||||
})
|
||||
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "cmd/admin/dist/index.html")
|
||||
})
|
||||
} else {
|
||||
r.Handle("/assets/*", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO http.StripPrefix("/admin/assets/",
|
||||
log.Println(r.URL.Path)
|
||||
d, err := assets.ReadFile("admin/dist/assets/index-e8823577.css")
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
w.Write(d)
|
||||
}))
|
||||
r.Get("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "image/x-icon")
|
||||
|
||||
if _, err := w.Write(favicon); err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
if _, err := w.Write(index); err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO
|
||||
w.Write([]byte("<h1>Hello World!</h1>"))
|
||||
})
|
||||
server := &http.Server{
|
||||
Handler: router,
|
||||
Addr: os.Getenv("MIGO_HOST"),
|
||||
WriteTimeout: 30 * time.Second,
|
||||
ReadTimeout: 30 * time.Second,
|
||||
}
|
||||
go func() {
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, os.Interrupt)
|
||||
<-sigint
|
||||
log.Println("Shutting down server")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||
|
||||
if err := http.ListenAndServe(":8080", router); err != nil {
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Printf("Error shutting down server gracefully: %v", err)
|
||||
}
|
||||
|
||||
cancel()
|
||||
}()
|
||||
log.Println("Starting server")
|
||||
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
log.Fatalf("Error starting server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user