Skip to content

Instantly share code, notes, and snippets.

@bengosney
Last active May 3, 2021 13:17
Show Gist options
  • Save bengosney/90232e42a833d4fd194e096b21161f5e to your computer and use it in GitHub Desktop.
Save bengosney/90232e42a833d4fd194e096b21161f5e to your computer and use it in GitHub Desktop.
serve current dir over https
.PHONY := serv, cleancd
.DEFAULT_GOAL := serv
SCRIPTFILE=simple-https-server.py
CERT=server.pem
IP=$(shell hostname -I | cut -f 1 -d " ")
DIR=$(shell pwd)
$(SCRIPTFILE):
@echo "" > $@
@echo "import BaseHTTPServer, SimpleHTTPServer" >> $@
@echo "import ssl" >> $@
@echo "" >> $@
@echo "httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)" >> $@
@echo "httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True)" >> $@
@echo "httpd.serve_forever()" >> $@
@echo "" >> $@
$(CERT):
openssl req -new -x509 -keyout $@ -out $@ -days 365 -nodes -subj '/CN=www.example.com/O=Example/C=GB'
serv: $(SCRIPTFILE) $(CERT)
@echo "Serving $(DIR) on https://$(IP):4443"
@python $(SCRIPTFILE)
clean:
@rm -f $(SCRIPTFILE)
@rm -f $(CERT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment