aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-12-21 17:09:29 +0700
committerShulhan <ms@kilabit.info>2021-12-21 17:09:57 +0700
commitf5a9a7934f3624763fce2094d291fbb97b96ddd1 (patch)
tree8fc383dfbd919a8a05e71d9eb45e82eb19a16633 /http_server.go
parentc2a65ee13d4f47365cb44b3301b223a743c07323 (diff)
downloadgorankusu-f5a9a7934f3624763fce2094d291fbb97b96ddd1.tar.xz
all: add feature to register custom navigation link
Using Trunks.RegisterNavLink, one can register custom link into left navigation menu.
Diffstat (limited to 'http_server.go')
-rw-r--r--http_server.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/http_server.go b/http_server.go
index e83e9a3..994872e 100644
--- a/http_server.go
+++ b/http_server.go
@@ -35,6 +35,13 @@ var (
ResponseType: libhttp.ResponseTypeJSON,
}
+ apiNavLinks = &libhttp.Endpoint{
+ Method: libhttp.RequestMethodGet,
+ Path: "/_trunks/api/navlinks",
+ RequestType: libhttp.RequestTypeNone,
+ ResponseType: libhttp.ResponseTypeJSON,
+ }
+
apiTargetRunHttp = &libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
Path: "/_trunks/api/target/run/http",
@@ -59,14 +66,23 @@ var (
func (trunks *Trunks) initHttpServer(isDevelopment bool) (err error) {
logp := "initHttpServer"
- httpdOpts := &libhttp.ServerOptions{
- Options: memfs.Options{
+ if memfsWWW == nil {
+ mfsOptions := memfs.Options{
Root: "_www",
Includes: []string{
`.*\.(js|html|ico|png)$`,
},
- Development: isDevelopment,
- },
+ Development: true,
+ }
+ memfsWWW, err = memfs.New(&mfsOptions)
+ if err != nil {
+ return fmt.Errorf("%s: %w", logp, err)
+ }
+ } else {
+ memfsWWW.Opts.Development = isDevelopment
+ }
+
+ httpdOpts := &libhttp.ServerOptions{
Memfs: memfsWWW,
Address: trunks.Env.ListenAddress,
}
@@ -93,6 +109,12 @@ func (trunks *Trunks) initHttpServer(isDevelopment bool) (err error) {
return fmt.Errorf("%s: %w", logp, err)
}
+ apiNavLinks.Call = trunks.apiNavLinks
+ err = trunks.Httpd.RegisterEndpoint(apiNavLinks)
+ if err != nil {
+ return fmt.Errorf("%s: %w", logp, err)
+ }
+
apiTargetRunHttp.Call = trunks.apiTargetRunHttp
err = trunks.Httpd.RegisterEndpoint(apiTargetRunHttp)
if err != nil {
@@ -168,6 +190,13 @@ func (trunks *Trunks) apiAttackResultGet(epr *libhttp.EndpointRequest) (resbody
return json.Marshal(&res)
}
+func (trunks *Trunks) apiNavLinks(epr *libhttp.EndpointRequest) (resbody []byte, err error) {
+ res := libhttp.EndpointResponse{}
+ res.Code = http.StatusOK
+ res.Data = trunks.navLinks
+ return json.Marshal(&res)
+}
+
func (trunks *Trunks) apiTargetRunHttp(epr *libhttp.EndpointRequest) ([]byte, error) {
req := &RunRequest{}
err := json.Unmarshal(epr.RequestBody, req)