Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
6d3932b4
Commit
6d3932b4
authored
Sep 18, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move webserver into its own package.
parent
21184556
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
sfu.go
sfu.go
+5
-8
webserver/webserver.go
webserver/webserver.go
+15
-11
No files found.
sfu.go
View file @
6d3932b4
...
...
@@ -17,17 +17,14 @@ import (
"sfu/disk"
"sfu/group"
"sfu/webserver"
)
var
httpAddr
string
var
staticRoot
string
var
dataDir
string
func
main
()
{
var
cpuprofile
,
memprofile
,
mutexprofile
string
var
cpuprofile
,
memprofile
,
mutexprofile
,
httpAddr
,
dataDir
string
flag
.
StringVar
(
&
httpAddr
,
"http"
,
":8443"
,
"web server `address`"
)
flag
.
StringVar
(
&
s
taticRoot
,
"static"
,
"./static/"
,
flag
.
StringVar
(
&
webserver
.
S
taticRoot
,
"static"
,
"./static/"
,
"web server root `directory`"
)
flag
.
StringVar
(
&
dataDir
,
"data"
,
"./data/"
,
"data `directory`"
)
...
...
@@ -84,10 +81,10 @@ func main() {
group
.
IceFilename
=
filepath
.
Join
(
dataDir
,
"ice-servers.json"
)
go
group
.
ReadPublicGroups
()
webserver
(
)
webserver
.
Serve
(
httpAddr
,
dataDir
)
terminate
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
terminate
,
syscall
.
SIGINT
,
syscall
.
SIGTERM
)
<-
terminate
s
hutdown
()
webserver
.
S
hutdown
()
}
webserver.go
→
webserver
/webserver
.go
View file @
6d3932b4
package
main
package
webserver
import
(
"bufio"
...
...
@@ -27,8 +27,10 @@ import (
var
server
*
http
.
Server
func
webserver
()
{
http
.
Handle
(
"/"
,
mungeHandler
{
http
.
FileServer
(
http
.
Dir
(
staticRoot
))})
var
StaticRoot
string
func
Serve
(
address
string
,
dataDir
string
)
{
http
.
Handle
(
"/"
,
mungeHandler
{
http
.
FileServer
(
http
.
Dir
(
StaticRoot
))})
http
.
HandleFunc
(
"/group/"
,
groupHandler
)
http
.
HandleFunc
(
"/recordings"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -44,10 +46,12 @@ func webserver() {
filepath
.
Join
(
dataDir
,
"ice-servers.json"
))
})
http
.
HandleFunc
(
"/public-groups.json"
,
publicHandler
)
http
.
HandleFunc
(
"/stats"
,
statsHandler
)
http
.
HandleFunc
(
"/stats"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
statsHandler
(
w
,
r
,
dataDir
)
})
server
=
&
http
.
Server
{
Addr
:
httpAddr
,
Addr
:
address
,
ReadHeaderTimeout
:
60
*
time
.
Second
,
IdleTimeout
:
120
*
time
.
Second
,
}
...
...
@@ -100,7 +104,7 @@ func notFound(w http.ResponseWriter) {
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
f
,
err
:=
os
.
Open
(
path
.
Join
(
s
taticRoot
,
"404.html"
))
f
,
err
:=
os
.
Open
(
path
.
Join
(
S
taticRoot
,
"404.html"
))
if
err
!=
nil
{
fmt
.
Fprintln
(
w
,
"<p>Not found</p>"
)
return
...
...
@@ -162,7 +166,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
return
}
http
.
ServeFile
(
w
,
r
,
filepath
.
Join
(
s
taticRoot
,
"sfu.html"
))
http
.
ServeFile
(
w
,
r
,
filepath
.
Join
(
S
taticRoot
,
"sfu.html"
))
}
func
publicHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -179,7 +183,7 @@ func publicHandler(w http.ResponseWriter, r *http.Request) {
return
}
func
getPassword
()
(
string
,
string
,
error
)
{
func
getPassword
(
dataDir
string
)
(
string
,
string
,
error
)
{
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
dataDir
,
"passwd"
))
if
err
!=
nil
{
return
""
,
""
,
err
...
...
@@ -207,8 +211,8 @@ func failAuthentication(w http.ResponseWriter, realm string) {
http
.
Error
(
w
,
"Haha!"
,
http
.
StatusUnauthorized
)
}
func
statsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
u
,
p
,
err
:=
getPassword
()
func
statsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
dataDir
string
)
{
u
,
p
,
err
:=
getPassword
(
dataDir
)
if
err
!=
nil
{
log
.
Printf
(
"Passwd: %v"
,
err
)
failAuthentication
(
w
,
"stats"
)
...
...
@@ -472,7 +476,7 @@ func serveGroupRecordings(w http.ResponseWriter, r *http.Request, f *os.File, gr
fmt
.
Fprintf
(
w
,
"</body></html>
\n
"
)
}
func
s
hutdown
()
{
func
S
hutdown
()
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
2
*
time
.
Second
)
defer
cancel
()
server
.
Shutdown
(
ctx
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment