12

Simple HTTP Server for local testing

 3 years ago
source link: http://www.mikechambers.com/blog/2012/04/08/simple-http-server-for-local-testing/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Simple HTTP Server for local testing

Sunday, April 8, 2012

I am currently playing around with the HTML5 FileSystem API, and have a need to test my files served via a web server. I could setup a virtual director for my local apache server, but given the number of simple tests and experiments I do, I wanted something easier that required little to no configuration and setup.

So, I put together a super simple script that uses python’s SimpleHTTPServer class.

Here is the script (requires that python is installed and in your path)

#!/bin/bash
 
python -m SimpleHTTPServer $1

To use it, just switch the the directory that contains your files and run:

http

This will open a simple webserver on port 8000.

You can optionally pass in the port like so:

http 2030

Which will start a simple web server listening on port 2030.

Again, this is something really simple, but also very useful. If you need to quickly test a file, just switch to the directory and run the script.

Btw, another work around for playing with the FileSystem APIs would be to pass the:

--allow-file-access-from-files

to Chrome when launching it.

Update 2/1/2016 : For python 3, the command is:

python -m http.server PORT

and thus the bash script would be:

#!/bin/bash
 
python -m http.server $1

If I get some time, Ill update the script to just automatically detect the version of python running.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK