Skip to content

Commit

Permalink
Go back to herokuish style deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 8, 2024
1 parent d8cd0a0 commit 134f572
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/heroku/heroku-buildpack-python
https://github.com/dokku/heroku-buildpack-nginx
File renamed without changes.
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.18
52 changes: 52 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /usr/bin/env python
import posixpath
import argparse
import urllib
import os

from http.server import SimpleHTTPRequestHandler
from http.server import HTTPServer


class RootedHTTPServer(HTTPServer):

def __init__(self, base_path, *args, **kwargs):
HTTPServer.__init__(self, *args, **kwargs)
self.RequestHandlerClass.base_path = base_path


class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):

def translate_path(self, path):
url_path = urllib.parse.urlparse(path).path
path = posixpath.normpath(urllib.parse.unquote(url_path))
words = [w for w in path.split('/') if w]
path = self.base_path
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir):
continue
path = os.path.join(path, word)
return path


def main(HandlerClass=RootedHTTPRequestHandler, ServerClass=RootedHTTPServer):
parser = argparse.ArgumentParser()
parser.add_argument('--port', '-p',
default=os.getenv('PORT', 5000),
type=int)
parser.add_argument('--dir', '-d', default=os.getcwd(), type=str)
args = parser.parse_args()

server_address = ('', args.port)

httpd = ServerClass(args.dir, server_address, HandlerClass)

sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever()


if __name__ == '__main__':
main()

0 comments on commit 134f572

Please sign in to comment.