Last active
May 3, 2021 13:17
-
-
Save bengosney/90232e42a833d4fd194e096b21161f5e to your computer and use it in GitHub Desktop.
serve current dir over https
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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