Skip to content

Commit

Permalink
Fix render
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 16, 2024
1 parent 1492b47 commit 5b5d3aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/serenity/cmd_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func export(profileName string) error {
if err != nil {
return err
}
encoder := json.NewEncoder(os.Stdout)
encoder := json.NewEncoderContext(globalCtx, os.Stdout)
encoder.SetIndent("", " ")
err = encoder.Encode(boxOptions)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions server/server_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"bytes"
"encoding/json"
"net/http"
"strings"

Expand All @@ -12,6 +11,7 @@ import (
boxOption "github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"

"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -74,8 +74,7 @@ func (s *Server) render(writer http.ResponseWriter, request *http.Request) {
s.accessLog(request, http.StatusNotFound, 0)
return
}
metadata := M.Detect(request.Header.Get("User-Agent"))
options, err := profile.Render(metadata)
options, err := profile.Render(M.Detect(request.Header.Get("User-Agent")))
if err != nil {
s.logger.Error(E.Cause(err, "render options"))
render.Status(request, http.StatusInternalServerError)
Expand All @@ -84,7 +83,7 @@ func (s *Server) render(writer http.ResponseWriter, request *http.Request) {
return
}
var buffer bytes.Buffer
encoder := json.NewEncoder(&buffer)
encoder := json.NewEncoderContext(s.ctx, &buffer)
encoder.SetIndent("", " ")
err = encoder.Encode(&options)
if err != nil {
Expand Down

0 comments on commit 5b5d3aa

Please sign in to comment.