🗑️ Clean up project

This commit is contained in:
2024-09-29 23:51:05 +08:00
parent 232ded4cd4
commit 28d3a3fa06
32 changed files with 95 additions and 395 deletions

View File

@ -63,7 +63,7 @@ func main() {
// Init sideload server
hypertext.RunServer(
sideload.InitSideload(),
viper.GetStringSlice("hypertext.sideload_ports"),
viper.GetStringSlice("sideload.ports"),
[]string{},
)

View File

@ -77,7 +77,7 @@ type CertificateConfig struct {
func RunServer(app *fiber.App, ports []string, securedPorts []string) {
var certs []CertificateConfig
raw, _ := jsoniter.Marshal(viper.Get("hypertext.certificate"))
jsoniter.Unmarshal(raw, &certs)
_ = jsoniter.Unmarshal(raw, &certs)
tlsCfg := &tls.Config{
MinVersion: tls.VersionTLS12,
@ -118,6 +118,8 @@ func RunServer(app *fiber.App, ports []string, securedPorts []string) {
}
}
}()
log.Info().Msgf("Listening for %s... http://0.0.0.0%s", app.Config().AppName, port)
}
for _, port := range securedPorts {
@ -131,5 +133,7 @@ func RunServer(app *fiber.App, ports []string, securedPorts []string) {
log.Panic().Err(err).Msg("An error occurred when listening hypertext tls ports.")
}
}()
log.Info().Msgf("Listening for %s... https://0.0.0.0%s", app.Config().AppName, port)
}
}

View File

@ -68,7 +68,7 @@
<div class="text-center">
{{embed}}
<footer class="mt-3 text-sm text-neutral">
<footer class="mt-3 text-sm">
<p>
Powered by
<a href="https://wiki.smartsheep.studio/roadsign/index.html" target="_blank" class="link link-primary">

View File

@ -14,4 +14,4 @@ func init() {
}
}
var AppVersion = "2.0.0-delta2"
var AppVersion = "2.1.0"

View File

@ -38,7 +38,7 @@ func makeHypertextResponse(c *fiber.Ctx, dest *Destination) error {
}
limit := time.Duration(num) * time.Millisecond
uri := dest.MakeUri(c)
uri := dest.BuildUri(c)
return proxy.Do(c, uri, &fasthttp.Client{
ReadTimeout: limit,
WriteTimeout: limit,

View File

@ -60,13 +60,13 @@ func (v *Destination) GetType() DestinationType {
func (v *Destination) GetRawUri() (string, url.Values) {
uri := strings.SplitN(v.Uri, "://", 2)[1]
data := strings.SplitN(uri, "?", 2)
data = append(data, " ") // Make data array least have two element
data = append(data, " ") // Make the data array least have two elements
qs, _ := url.ParseQuery(data[1])
return data[0], qs
}
func (v *Destination) MakeUri(ctx *fiber.Ctx) string {
func (v *Destination) BuildUri(ctx *fiber.Ctx) string {
var queries []string
for k, v := range ctx.Queries() {
parsed, _ := url.QueryUnescape(v)
@ -85,5 +85,5 @@ func (v *Destination) MakeUri(ctx *fiber.Ctx) string {
}
func (v *Destination) MakeWebsocketUri(ctx *fiber.Ctx) string {
return strings.Replace(v.MakeUri(ctx), "http", "ws", 1)
return strings.Replace(v.BuildUri(ctx), "http", "ws", 1)
}

View File

@ -2,15 +2,11 @@ package sideload
import (
"fmt"
"git.solsynth.dev/goatworks/roadsign/pkg/sideload/view"
"github.com/gofiber/fiber/v2/middleware/filesystem"
jsoniter "github.com/json-iterator/go"
"net/http"
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/logger"
jsoniter "github.com/json-iterator/go"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
@ -25,7 +21,7 @@ func InitSideload() *fiber.App {
JSONEncoder: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal,
ProxyHeader: fiber.HeaderXForwardedFor,
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
TrustedProxies: viper.GetStringSlice("security.sideload_trusted_proxies"),
TrustedProxies: viper.GetStringSlice("sideload.trusted_proxies"),
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
})
@ -52,7 +48,7 @@ func InitSideload() *fiber.App {
cgi.Get("/regions", getRegions)
cgi.Get("/regions/cfg/:id", getRegionConfig)
cgi.Get("/applications", getApplications)
cgi.Get("/applications/logs/:id", getApplicationLogs)
cgi.Get("/applications/:id/logs", getApplicationLogs)
cgi.Post("/reload", doReload)
}
@ -63,12 +59,5 @@ func InitSideload() *fiber.App {
webhooks.Put("/sync/:slug", doSync)
}
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(view.FS),
PathPrefix: "dist",
Index: "index.html",
NotFoundFile: "dist/index.html",
}))
return app
}

View File

@ -1,27 +0,0 @@
# 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?
*.lock
package-lock.json

View File

@ -1,6 +0,0 @@
package view
import "embed"
//go:embed all:dist
var FS embed.FS

View File

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

View File

@ -1,24 +0,0 @@
{
"name": "roadsign-sideload",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@solidjs/router": "^0.10.10",
"solid-js": "^1.8.7"
},
"devDependencies": {
"autoprefixer": "^10.4.17",
"daisyui": "^4.6.0",
"postcss": "^8.4.33",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vite-plugin-solid": "^2.8.0"
}
}

View File

@ -1,6 +0,0 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

View File

@ -1,3 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@ -1,17 +0,0 @@
import "./index.css";
/* @refresh reload */
import { render } from "solid-js/web";
import { Route, Router } from "@solidjs/router";
import RootLayout from "./layouts/RootLayout";
import Dashboard from "./pages/dashboard";
const root = document.getElementById("root");
render(() => (
<Router root={RootLayout}>
<Route path="/" component={Dashboard} />
</Router>
), root!);

View File

@ -1,11 +0,0 @@
import Navbar from "./shared/Navbar";
export default function RootLayout(props: any) {
return (
<div>
<Navbar />
<main class="h-[calc(100vh-64px)]">{props.children}</main>
</div>
);
}

View File

@ -1,62 +0,0 @@
import { For } from "solid-js";
interface MenuItem {
label: string;
href: string;
}
export default function Navbar() {
const nav: MenuItem[] = [{ label: "Dashboard", href: "/" }];
return (
<div class="navbar bg-base-100 shadow-md">
<div class="navbar-start">
<div class="dropdown">
<div tabIndex={0} role="button" class="btn btn-ghost lg:hidden">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 6h16M4 12h8m-8 6h16"
/>
</svg>
</div>
<ul
tabIndex={0}
class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"
>
<For each={nav}>
{(item) => (
<li>
<a href={item.href}>{item.label}</a>
</li>
)}
</For>
</ul>
</div>
<a href="/" class="btn btn-ghost text-xl">
RoadSign
</a>
</div>
<div class="navbar-center hidden lg:flex">
<ul class="menu menu-horizontal px-1">
<For each={nav}>
{(item) => (
<li>
<a href={item.href}>{item.label}</a>
</li>
)}
</For>
</ul>
</div>
<div class="navbar-end"></div>
</div>
);
}

View File

@ -1,10 +0,0 @@
export default function Dashboard() {
return (
<div class="h-full w-full flex justify-center items-center">
<div class="max-w-96 text-center">
<h1 class="text-2xl font-bold">Hold on</h1>
<p>Our brand new sideload administration panel is still in progress. For now, you can use sideload api and roadsign cli.</p>
</div>
</div>
)
}

View File

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

View File

@ -1,57 +0,0 @@
/** @type {import("tailwindcss").Config} */
export default {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {}
},
daisyui: {
themes: [
{
light: {
primary: "#4750a3",
secondary: "#93c5fd",
accent: "#0f766e",
info: "#67e8f9",
success: "#15803d",
warning: "#f97316",
error: "#dc2626",
neutral: "#2B3440",
"secondary-content": "oklch(98.71% 0.0106 342.55)",
"neutral-content": "#D7DDE4",
"base-100": "oklch(100% 0 0)",
"base-200": "#F2F2F2",
"base-300": "#E5E6E6",
"base-content": "#1f2937",
"color-scheme": "light",
"--rounded-box": "0",
"--rounded-btn": "0",
"--rounded-badge": "0",
"--tab-radius": "0"
}
},
{
dark: {
primary: "#4750a3",
secondary: "#93c5fd",
accent: "#0f766e",
info: "#67e8f9",
success: "#15803d",
warning: "#f97316",
error: "#dc2626",
neutral: "#2a323c",
"neutral-content": "#A6ADBB",
"base-100": "#1d232a",
"base-200": "#191e24",
"base-300": "#15191e",
"base-content": "#A6ADBB",
"color-scheme": "dark",
"--rounded-box": "0",
"--rounded-btn": "0",
"--rounded-badge": "0",
"--tab-radius": "0"
}
}
]
},
plugins: [require("daisyui")]
}

View File

@ -1,26 +0,0 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

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

View File

@ -1,6 +0,0 @@
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
export default defineConfig({
plugins: [solid()],
})