mirror of
https://github.com/postmannen/ctrl.git
synced 2025-04-09 10:24:17 +00:00
expose datafolder via http
This commit is contained in:
parent
709c69313a
commit
10d28f6ec1
2 changed files with 31 additions and 2 deletions
|
@ -101,10 +101,10 @@ type Configuration struct {
|
|||
CentralNodeName string
|
||||
// Path to the certificate of the root CA
|
||||
RootCAPath string
|
||||
|
||||
// Full path to the NKEY's seed file
|
||||
NkeySeedFile string
|
||||
|
||||
// The host and port to expose the data folder
|
||||
ExposeDataFolder string
|
||||
// Make the current node send hello messages to central at given interval in seconds
|
||||
StartPubREQHello int
|
||||
// Start the central error logger.
|
||||
|
@ -157,6 +157,7 @@ func newConfigurationDefaults() Configuration {
|
|||
CentralNodeName: "",
|
||||
RootCAPath: "",
|
||||
NkeySeedFile: "",
|
||||
ExposeDataFolder: "",
|
||||
StartSubREQErrorLog: flagNodeSlice{Values: []Node{}},
|
||||
StartSubREQHello: flagNodeSlice{OK: true, Values: []Node{"*"}},
|
||||
StartSubREQToFileAppend: flagNodeSlice{OK: true, Values: []Node{"*"}},
|
||||
|
@ -207,6 +208,7 @@ func (c *Configuration) CheckFlags() error {
|
|||
flag.StringVar(&c.CentralNodeName, "centralNodeName", fc.CentralNodeName, "The name of the central node to receive messages published by this node")
|
||||
flag.StringVar(&c.RootCAPath, "rootCAPath", fc.RootCAPath, "If TLS, enter the path for where to find the root CA certificate")
|
||||
flag.StringVar(&c.NkeySeedFile, "nkeySeedFile", fc.NkeySeedFile, "The full path of the nkeys seed file")
|
||||
flag.StringVar(&c.ExposeDataFolder, "exposeDataFolder", fc.ExposeDataFolder, "If set the data folder will be exposed on the given host:port. Default value is not exposed at all")
|
||||
|
||||
flag.IntVar(&c.StartPubREQHello, "startPubREQHello", fc.StartPubREQHello, "Make the current node send hello messages to central at given interval in seconds")
|
||||
|
||||
|
|
27
server.go
27
server.go
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -235,6 +236,12 @@ func (s *server) Start() {
|
|||
time.Sleep(time.Second * 1)
|
||||
s.processes.printProcessesMap()
|
||||
|
||||
// Start exposing the the data folder via HTTP if flag is set.
|
||||
if s.configuration.ExposeDataFolder != "" {
|
||||
log.Printf("info: Starting expose of data folder via HTTP\n")
|
||||
go s.exposeDataFolder(s.ctx)
|
||||
}
|
||||
|
||||
// Start the processing of new messages from an input channel.
|
||||
s.routeMessagesToProcess("./incomingBuffer.db", s.toRingbufferCh)
|
||||
|
||||
|
@ -410,3 +417,23 @@ func (s *server) routeMessagesToProcess(dbFileName string, newSAM chan []subject
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *server) exposeDataFolder(ctx context.Context) {
|
||||
//create a file server, and serve the files found in ./
|
||||
fd := http.FileServer(http.Dir(s.configuration.SubscribersDataFolder))
|
||||
http.Handle("/", fd)
|
||||
|
||||
// we create a net.Listen type to use later with the http.Serve function.
|
||||
nl, err := net.Listen("tcp", s.configuration.ExposeDataFolder)
|
||||
if err != nil {
|
||||
log.Println("error: starting net.Listen: ", err)
|
||||
}
|
||||
|
||||
// start the web server with http.Serve instead of the usual http.ListenAndServe
|
||||
err = http.Serve(nl, nil)
|
||||
if err != nil {
|
||||
log.Printf("Error: failed to start web server: %v\n", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue