mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 04:22:23 +08:00
platform: Enable Clash API support by default
This commit is contained in:
parent
f43d0141f3
commit
1363e16312
6
box.go
6
box.go
|
@ -51,7 +51,7 @@ func New(options Options) (*Box, error) {
|
||||||
applyDebugOptions(common.PtrValueOrDefault(experimentalOptions.Debug))
|
applyDebugOptions(common.PtrValueOrDefault(experimentalOptions.Debug))
|
||||||
var needClashAPI bool
|
var needClashAPI bool
|
||||||
var needV2RayAPI bool
|
var needV2RayAPI bool
|
||||||
if experimentalOptions.ClashAPI != nil && experimentalOptions.ClashAPI.ExternalController != "" {
|
if experimentalOptions.ClashAPI != nil || options.PlatformInterface != nil {
|
||||||
needClashAPI = true
|
needClashAPI = true
|
||||||
}
|
}
|
||||||
if experimentalOptions.V2RayAPI != nil && experimentalOptions.V2RayAPI.Listen != "" {
|
if experimentalOptions.V2RayAPI != nil && experimentalOptions.V2RayAPI.Listen != "" {
|
||||||
|
@ -143,7 +143,7 @@ func New(options Options) (*Box, error) {
|
||||||
preServices := make(map[string]adapter.Service)
|
preServices := make(map[string]adapter.Service)
|
||||||
postServices := make(map[string]adapter.Service)
|
postServices := make(map[string]adapter.Service)
|
||||||
if needClashAPI {
|
if needClashAPI {
|
||||||
clashServer, err := experimental.NewClashServer(ctx, router, logFactory.(log.ObservableFactory), common.PtrValueOrDefault(options.Experimental.ClashAPI))
|
clashServer, err := experimental.NewClashServer(ctx, router, logFactory.(log.ObservableFactory), common.PtrValueOrDefault(experimentalOptions.ClashAPI))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.Cause(err, "create clash api server")
|
return nil, E.Cause(err, "create clash api server")
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ func New(options Options) (*Box, error) {
|
||||||
preServices["clash api"] = clashServer
|
preServices["clash api"] = clashServer
|
||||||
}
|
}
|
||||||
if needV2RayAPI {
|
if needV2RayAPI {
|
||||||
v2rayServer, err := experimental.NewV2RayServer(logFactory.NewLogger("v2ray-api"), common.PtrValueOrDefault(options.Experimental.V2RayAPI))
|
v2rayServer, err := experimental.NewV2RayServer(logFactory.NewLogger("v2ray-api"), common.PtrValueOrDefault(experimentalOptions.V2RayAPI))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.Cause(err, "create v2ray api server")
|
return nil, E.Cause(err, "create v2ray api server")
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ type Server struct {
|
||||||
cacheID string
|
cacheID string
|
||||||
cacheFile adapter.ClashCacheFile
|
cacheFile adapter.ClashCacheFile
|
||||||
|
|
||||||
|
externalController bool
|
||||||
externalUI string
|
externalUI string
|
||||||
externalUIDownloadURL string
|
externalUIDownloadURL string
|
||||||
externalUIDownloadDetour string
|
externalUIDownloadDetour string
|
||||||
|
@ -71,6 +72,7 @@ func NewServer(ctx context.Context, router adapter.Router, logFactory log.Observ
|
||||||
trafficManager: trafficManager,
|
trafficManager: trafficManager,
|
||||||
mode: strings.ToLower(options.DefaultMode),
|
mode: strings.ToLower(options.DefaultMode),
|
||||||
storeSelected: options.StoreSelected,
|
storeSelected: options.StoreSelected,
|
||||||
|
externalController: options.ExternalController != "",
|
||||||
storeFakeIP: options.StoreFakeIP,
|
storeFakeIP: options.StoreFakeIP,
|
||||||
externalUIDownloadURL: options.ExternalUIDownloadURL,
|
externalUIDownloadURL: options.ExternalUIDownloadURL,
|
||||||
externalUIDownloadDetour: options.ExternalUIDownloadDetour,
|
externalUIDownloadDetour: options.ExternalUIDownloadDetour,
|
||||||
|
@ -146,18 +148,20 @@ func (s *Server) PreStart() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
s.checkAndDownloadExternalUI()
|
if s.externalController {
|
||||||
listener, err := net.Listen("tcp", s.httpServer.Addr)
|
s.checkAndDownloadExternalUI()
|
||||||
if err != nil {
|
listener, err := net.Listen("tcp", s.httpServer.Addr)
|
||||||
return E.Cause(err, "external controller listen error")
|
if err != nil {
|
||||||
}
|
return E.Cause(err, "external controller listen error")
|
||||||
s.logger.Info("restful api listening at ", listener.Addr())
|
|
||||||
go func() {
|
|
||||||
err = s.httpServer.Serve(listener)
|
|
||||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
||||||
s.logger.Error("external controller serve error: ", err)
|
|
||||||
}
|
}
|
||||||
}()
|
s.logger.Info("restful api listening at ", listener.Addr())
|
||||||
|
go func() {
|
||||||
|
err = s.httpServer.Serve(listener)
|
||||||
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
s.logger.Error("external controller serve error: ", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user