summaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
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)