Skip to content

Commit

Permalink
feat: completed web server
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeStarks committed Aug 10, 2022
1 parent 5224d9e commit debd9a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (s *Server) Serve() {
log.Println("Connection failed:", err)
continue
}
log.Println("Connected")

// Handle connection in a new goroutine
go s.process(conn)
Expand Down
9 changes: 4 additions & 5 deletions app/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ func (s *Services) ServeServices() {

}

// if service.Tunnelled {
// // tools.Tunnel(service.Listeners)
// }
// Tunnelling
}
}

Expand All @@ -114,15 +112,16 @@ func (s *Services) ConnectToServer(addr string) (net.Conn, error) {
// Serve static Services, and return their port numbers
func (s *Services) ServeStatic(dir string) int {
fs := http.FileServer(http.Dir(dir))
http.Handle("/", fs)
mux := http.NewServeMux()
mux.Handle("/", fs)

// Get and listen on the next port number
portNo := s.nextPN
for {
// Dial the port number to see if it's available
_, err := net.Dial("tcp", fmt.Sprintf("[::]:%d", portNo))
if err != nil {
go http.ListenAndServe(fmt.Sprintf(":%d", portNo), fs)
go http.ListenAndServe(fmt.Sprintf(":%d", portNo), mux)
break
}
// If it's already in use, try the next port
Expand Down
10 changes: 8 additions & 2 deletions cmd/services.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

Expand All @@ -24,8 +25,13 @@ var (
if f, _ := flags.GetBool("add"); f {
// Open the app's configuration file "conoid.yml"
wd, _ := os.Getwd()
appFile := filepath.Join(wd, "conoid.yml")
services.Add(appFile)
pathToConf := filepath.Join(wd, "conoid.yml")
// Check if such file exists
if _, err := os.Stat(pathToConf); err != nil {
fmt.Println("A file named \"conoid.yml\" could not be found in the current directory")
return
}
services.Add(pathToConf)
return
}
},
Expand Down

0 comments on commit debd9a8

Please sign in to comment.