Skip to content

Commit

Permalink
Server always returns index.html instead of 404
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagara committed Jul 29, 2016
1 parent feface7 commit 6b47d81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You'll need an http server in order to run this.

If you have node.js and [npm](https://npmjs.com/) available, you can run `npm install http-server` and then run `http-server`. Now you can open https://localhost:8080 in your browser.

If you are on Mac OSX you can also run `python -m SimpleHTTPServer` in the project directory. Now open https://localhost:8000 in your browser.
If you are on Mac OSX you can also run `python server.py` in the project directory. Now open https://localhost:8000 in your browser.

If you use any other server and serve this in a subdirectory, make sure to set the appropriate value in the `<base>` tag on `index.html`

Expand Down
18 changes: 18 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import SimpleHTTPServer, SocketServer
import os

PORT = 8000

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
"""Return the requested file if it exists otherwise return index.html"""
if os.access('.' + os.sep + self.path, os.R_OK):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self);
else:
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write(open('index.html').read())

httpd = SocketServer.TCPServer(('', PORT), MyHandler)
httpd.serve_forever()

0 comments on commit 6b47d81

Please sign in to comment.