Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mpv_sync
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stefan Kraus
mpv_sync
Commits
b988e782
Commit
b988e782
authored
Apr 5, 2021
by
Stefan Kraus
Browse files
Options
Downloads
Patches
Plain Diff
Let reverse proxy handle SSL by default
parent
9be31dbf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/server.py
+20
-7
20 additions, 7 deletions
server/server.py
with
20 additions
and
7 deletions
server/server.py
+
20
−
7
View file @
b988e782
...
...
@@ -11,10 +11,16 @@ from enum import Enum, auto
from
aioconsole
import
ainput
LOCAL
=
False
# Port the websocket will listen on
PORT
=
8432
PATH_CERTCHAIN
=
"
/etc/letsencrypt/live/www.mpvsync.de/fullchain.pem
"
PATH_PRIVATE_KEY
=
"
/etc/letsencrypt/live/www.mpvsync.de/privkey.pem
"
# Shall SSL be handled by the server itself?
# Can be disabled if you use a reverse proxy who does ssl for you
ENABLE_SSL
=
False
# In case you set ENABLE_SSL = True, set paths to your certchain and private key
PATH_CERTCHAIN
=
"
/path/to/ssl/certchain.pem
"
PATH_PRIVATE_KEY
=
"
/path/to/ssl/privatekey.pem
"
PLAY_REQUEST
=
{
"
command
"
:
"
play
"
}
PAUSE_REQUEST
=
{
"
command
"
:
"
pause
"
}
...
...
@@ -219,15 +225,22 @@ async def handle(ws: websockets.WebSocketServerProtocol, path: str) -> None:
def
main
():
ssl_context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_TLS_SERVER
)
ssl_context
.
load_cert_chain
(
PATH_CERTCHAIN
,
PATH_PRIVATE_KEY
)
hostname
=
"
127.0.0.1
"
if
LOCAL
else
None
hostname
=
None
# Listen 'publicly'
port
=
PORT
try
:
async
def
async_main
():
if
ENABLE_SSL
:
ssl_context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_TLS_SERVER
)
ssl_context
.
load_cert_chain
(
PATH_CERTCHAIN
,
PATH_PRIVATE_KEY
)
# wss connection, public one
await
websockets
.
serve
(
handle
,
hostname
,
port
,
ssl
=
ssl_context
)
else
:
# ws connection without TLS, for development only!
await
websockets
.
serve
(
handle
,
hostname
,
port
)
await
console_input
()
asyncio
.
run
(
async_main
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment