Skip to content

Commit

Permalink
Added source code
Browse files Browse the repository at this point in the history
Added source code
  • Loading branch information
howCodeORG committed Mar 5, 2018
1 parent eb13c67 commit f665259
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Simple Python Web Server
========================

This is the source code for howCode's simple Python Web Server.

You can watch the video that accompanies this source code here: https://youtu.be/hFNZ6kdBgO0
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello world!</title>
</head>
<body>
<h1>Index page!</h1>
</body>
</html>
20 changes: 20 additions & 0 deletions serv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from http.server import HTTPServer, BaseHTTPRequestHandler


class Serv(BaseHTTPRequestHandler):

def do_GET(self):
if self.path == '/':
self.path = '/index.html'
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
except:
file_to_open = "File not found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))


httpd = HTTPServer(('localhost', 8080), Serv)
httpd.serve_forever()
10 changes: 10 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello world!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

0 comments on commit f665259

Please sign in to comment.