contrib: systemd/python http for localhost
This commit is contained in:
		
							parent
							
								
									528c9cbf39
								
							
						
					
					
						commit
						6564b86181
					
				| 
						 | 
				
			
			@ -155,6 +155,11 @@ Example: ./build.sh -u https://start.domain.tld -d static -t "STILDE - StartPage
 | 
			
		|||
 | 
			
		||||
- **On mobile devices** you can open/close the input and you keyboard by a touch on the logo.
 | 
			
		||||
 | 
			
		||||
## Contrib
 | 
			
		||||
 | 
			
		||||
I put the files I use to serve Stilde on the localhost with a python http server and systemd. You will need to correct the locations and provide a certificate.
 | 
			
		||||
 | 
			
		||||
It's not part of the main folder because it's just a niche way to use Stilde.
 | 
			
		||||
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										29
									
								
								contrib/serve-https.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								contrib/serve-https.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
import os
 | 
			
		||||
import http.server
 | 
			
		||||
import socketserver
 | 
			
		||||
import ssl
 | 
			
		||||
 | 
			
		||||
# Set the path to the directory you want to serve
 | 
			
		||||
directory_to_serve = os.path.expanduser('~/.local/opt/stilde')
 | 
			
		||||
 | 
			
		||||
# Set the port for your HTTPS server
 | 
			
		||||
port = 1984
 | 
			
		||||
 | 
			
		||||
# Specify the SSL/TLS certificate and key files
 | 
			
		||||
certfile = os.path.expanduser('~/.ssl/MYRootCA/localhost.crt')
 | 
			
		||||
keyfile = os.path.expanduser('~/.ssl/MYRootCA/localhost.key')
 | 
			
		||||
 | 
			
		||||
# Create a custom handler to use the SSL context
 | 
			
		||||
class MyHandler(http.server.SimpleHTTPRequestHandler):
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, directory=directory_to_serve, **kwargs)
 | 
			
		||||
 | 
			
		||||
# Create an SSL context
 | 
			
		||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
 | 
			
		||||
ssl_context.load_cert_chain(certfile=certfile, keyfile=keyfile)
 | 
			
		||||
 | 
			
		||||
# Create the HTTPS server
 | 
			
		||||
with socketserver.TCPServer(("127.0.1.1", port), MyHandler) as httpd:
 | 
			
		||||
    httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)
 | 
			
		||||
    print(f"Serving directory at https://127.0.1.1:{port}")
 | 
			
		||||
    httpd.serve_forever()
 | 
			
		||||
							
								
								
									
										18
									
								
								contrib/stilde.service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								contrib/stilde.service
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
[Unit]
 | 
			
		||||
Description=Stilde startpage Web server
 | 
			
		||||
PartOf=graphical-session.target
 | 
			
		||||
After=journal.service
 | 
			
		||||
 | 
			
		||||
[Service]
 | 
			
		||||
Type=simple
 | 
			
		||||
Restart=no
 | 
			
		||||
WorkingDirectory=%h/.local/opt/stilde
 | 
			
		||||
ExecStart=python3 %h/.local/opt/stilde/serve-https.py
 | 
			
		||||
 | 
			
		||||
StandardOutput=journal
 | 
			
		||||
StandardError=journal
 | 
			
		||||
SyslogIdentifier=stilde
 | 
			
		||||
Slice=background.slice
 | 
			
		||||
 | 
			
		||||
[Install]
 | 
			
		||||
WantedBy=graphical-session.target
 | 
			
		||||
		Loading…
	
		Reference in a new issue