mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-07 07:42:45 +01:00
Fix routing (#43)
This commit is contained in:
@@ -5,8 +5,23 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func VueStatic(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
handler := http.FileServer(http.FS(fsys))
|
||||||
|
|
||||||
|
if strings.HasPrefix(r.URL.Path, "/static/") {
|
||||||
|
handler = http.StripPrefix("/static/", handler)
|
||||||
|
} else {
|
||||||
|
r.URL.Path = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Static(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
|
func Static(fsys fs.FS) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.FileServer(http.FS(fsys)).ServeHTTP(w, r)
|
http.FileServer(http.FS(fsys)).ServeHTTP(w, r)
|
||||||
|
|||||||
35
server.go
35
server.go
@@ -3,7 +3,6 @@ package catalyst
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -116,35 +115,33 @@ func New(hooks *hooks.Hooks, config *Config) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupAPI(catalystService *service.Service, catalystStorage *storage.Storage, catalystDatabase *database.Database, dbConfig *database.Config, bus *bus.Bus, config *Config) (chi.Router, error) {
|
func setupAPI(catalystService *service.Service, catalystStorage *storage.Storage, catalystDatabase *database.Database, dbConfig *database.Config, bus *bus.Bus, config *Config) (chi.Router, error) {
|
||||||
// create server
|
middlewares := []func(next http.Handler) http.Handler{Authenticate(catalystDatabase, config.Auth), AuthorizeBlockedUser()}
|
||||||
allowAll := cors.AllowAll().Handler
|
|
||||||
apiServer := api.NewServer(
|
|
||||||
catalystService,
|
|
||||||
AuthorizeRole,
|
|
||||||
allowAll, Authenticate(catalystDatabase, config.Auth), AuthorizeBlockedUser(),
|
|
||||||
)
|
|
||||||
|
|
||||||
apiServer.With(AuthorizeRole([]string{role.FileReadWrite.String()})).Head("/files/{ticketID}/tusd/{id}", tusdUpload(catalystDatabase, bus, catalystStorage.S3(), config.ExternalAddress))
|
// create server
|
||||||
apiServer.With(AuthorizeRole([]string{role.FileReadWrite.String()})).Patch("/files/{ticketID}/tusd/{id}", tusdUpload(catalystDatabase, bus, catalystStorage.S3(), config.ExternalAddress))
|
apiServerMiddleware := []func(next http.Handler) http.Handler{cors.AllowAll().Handler}
|
||||||
apiServer.With(AuthorizeRole([]string{role.FileReadWrite.String()})).Post("/files/{ticketID}/tusd", tusdUpload(catalystDatabase, bus, catalystStorage.S3(), config.ExternalAddress))
|
apiServerMiddleware = append(apiServerMiddleware, middlewares...)
|
||||||
apiServer.With(AuthorizeRole([]string{role.FileReadWrite.String()})).Post("/files/{ticketID}/upload", upload(catalystDatabase, catalystStorage.S3(), catalystStorage.Uploader()))
|
apiServer := api.NewServer(catalystService, AuthorizeRole, apiServerMiddleware...)
|
||||||
apiServer.With(AuthorizeRole([]string{role.FileReadWrite.String()})).Get("/files/{ticketID}/download/{key}", download(catalystStorage.Downloader()))
|
|
||||||
|
fileReadWrite := AuthorizeRole([]string{role.FileReadWrite.String()})
|
||||||
|
tudHandler := tusdUpload(catalystDatabase, bus, catalystStorage.S3(), config.ExternalAddress)
|
||||||
|
apiServer.With(fileReadWrite).Head("/files/{ticketID}/tusd/{id}", tudHandler)
|
||||||
|
apiServer.With(fileReadWrite).Patch("/files/{ticketID}/tusd/{id}", tudHandler)
|
||||||
|
apiServer.With(fileReadWrite).Post("/files/{ticketID}/tusd", tudHandler)
|
||||||
|
apiServer.With(fileReadWrite).Post("/files/{ticketID}/upload", upload(catalystDatabase, catalystStorage.S3(), catalystStorage.Uploader()))
|
||||||
|
apiServer.With(fileReadWrite).Get("/files/{ticketID}/download/{key}", download(catalystStorage.Downloader()))
|
||||||
|
|
||||||
apiServer.With(AuthorizeRole([]string{role.BackupRead.String()})).Get("/backup/create", backupHandler(catalystStorage, dbConfig))
|
apiServer.With(AuthorizeRole([]string{role.BackupRead.String()})).Get("/backup/create", backupHandler(catalystStorage, dbConfig))
|
||||||
apiServer.With(AuthorizeRole([]string{role.BackupRestore.String()})).Post("/backup/restore", restoreHandler(catalystStorage, catalystDatabase, dbConfig))
|
apiServer.With(AuthorizeRole([]string{role.BackupRestore.String()})).Post("/backup/restore", restoreHandler(catalystStorage, catalystDatabase, dbConfig))
|
||||||
|
|
||||||
server := chi.NewRouter()
|
server := chi.NewRouter()
|
||||||
server.Use(middleware.RequestID, middleware.RealIP, middleware.Logger, middleware.Recoverer, allowAll)
|
server.Use(middleware.RequestID, middleware.RealIP, middleware.Logger, middleware.Recoverer, cors.AllowAll().Handler)
|
||||||
server.Mount("/api", apiServer)
|
server.Mount("/api", apiServer)
|
||||||
|
|
||||||
server.Get("/callback", callback(config.Auth))
|
server.Get("/callback", callback(config.Auth))
|
||||||
server.With(Authenticate(catalystDatabase, config.Auth), AuthorizeBlockedUser()).Handle("/wss", handleWebSocket(bus))
|
server.With(middlewares...).Handle("/wss", handleWebSocket(bus))
|
||||||
|
|
||||||
fsys, _ := fs.Sub(ui.UI, "dist")
|
fsys, _ := fs.Sub(ui.UI, "dist")
|
||||||
server.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
server.With(middlewares...).NotFound(api.VueStatic(fsys))
|
||||||
log.Println("not found", r.URL.RawPath)
|
|
||||||
Authenticate(catalystDatabase, config.Auth)(AuthorizeBlockedUser()(http.HandlerFunc(api.Static(fsys)))).ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
|
|
||||||
return server, nil
|
return server, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<link rel="icon" href="/flask.png?v=1">
|
|
||||||
<title>Catalyst</title>
|
<title>Catalyst</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -12,8 +11,5 @@
|
|||||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script>let global = globalThis;</script>
|
|
||||||
<script type="module" src="./src/main.ts"></script>
|
|
||||||
<!-- built files will be auto injected -->
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<v-list>
|
<v-list>
|
||||||
<v-list-item class="px-2" :to="{ name: 'Home' }">
|
<v-list-item class="px-2" :to="{ name: 'Home' }">
|
||||||
<v-list-item-avatar rounded="0">
|
<v-list-item-avatar rounded="0">
|
||||||
<v-img src="/flask_white.svg" :width="40"></v-img>
|
<v-img src="/static/flask_white.svg" :width="40"></v-img>
|
||||||
</v-list-item-avatar>
|
</v-list-item-avatar>
|
||||||
<v-list-item-content>
|
<v-list-item-content>
|
||||||
<v-list-item-title class="title">
|
<v-list-item-title class="title">
|
||||||
@@ -132,9 +132,7 @@
|
|||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
</v-app-bar>
|
</v-app-bar>
|
||||||
<div>
|
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
</div>
|
|
||||||
<v-snackbar v-model="snackbar" :color="$store.state.alert.type" :timeout="$store.state.alert.type === 'error' ? -1 : 5000" outlined>
|
<v-snackbar v-model="snackbar" :color="$store.state.alert.type" :timeout="$store.state.alert.type === 'error' ? -1 : 5000" outlined>
|
||||||
<b style="display: block">{{ $store.state.alert.name | capitalize }}</b>
|
<b style="display: block">{{ $store.state.alert.name | capitalize }}</b>
|
||||||
{{ $store.state.alert.detail }}
|
{{ $store.state.alert.detail }}
|
||||||
@@ -190,6 +188,8 @@ export default Vue.extend({
|
|||||||
return this.$store.state.showAlert
|
return this.$store.state.showAlert
|
||||||
},
|
},
|
||||||
crumbs: function() {
|
crumbs: function() {
|
||||||
|
this.$route.name
|
||||||
|
|
||||||
let pathArray = this.$route.path.split("/")
|
let pathArray = this.$route.path.split("/")
|
||||||
pathArray.shift()
|
pathArray.shift()
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import TicketType from '../views/TicketType.vue';
|
|||||||
import TicketTypeList from "@/views/TicketTypeList.vue";
|
import TicketTypeList from "@/views/TicketTypeList.vue";
|
||||||
import TaskList from "@/views/TaskList.vue";
|
import TaskList from "@/views/TaskList.vue";
|
||||||
import Settings from "@/views/Settings.vue";
|
import Settings from "@/views/Settings.vue";
|
||||||
|
import NotFound from "@/views/NotFound.vue";
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
@@ -229,7 +230,6 @@ const routes: Array<RouteConfig> = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/dashboards",
|
path: "/dashboards",
|
||||||
name: "DashboardList",
|
name: "DashboardList",
|
||||||
@@ -264,6 +264,13 @@ const routes: Array<RouteConfig> = [
|
|||||||
component: Graph,
|
component: Graph,
|
||||||
meta: { title: "Graph" },
|
meta: { title: "Graph" },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '*',
|
||||||
|
name: "Not Found",
|
||||||
|
component: NotFound,
|
||||||
|
meta: { title: "Not Found" },
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
|
|||||||
13
ui/src/views/NotFound.vue
Normal file
13
ui/src/views/NotFound.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
<v-main>
|
||||||
|
<div class="fill-height d-flex flex-row align-center justify-center">
|
||||||
|
<h1>Page not found :(</h1>
|
||||||
|
</div>
|
||||||
|
</v-main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "NotFound"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
publicPath: "/static/",
|
||||||
transpileDependencies: ["vuetify", "@koumoul/vjsf"],
|
transpileDependencies: ["vuetify", "@koumoul/vjsf"],
|
||||||
pwa: {
|
pwa: {
|
||||||
name: "Catalyst",
|
name: "Catalyst",
|
||||||
|
|||||||
Reference in New Issue
Block a user