All developers want to just be able to "double click" an index.html page to test it.
Its never that easy... I'm sure a lot of people reading this have seen this error:
I love SEO so let me type out what the image says:
XMLHttpRequest cannot load [--url--] . Recieved an invalid response. Origin 'null' is therefore not allowed access.
Sometimes you just want a simple sandbox, you dont want a server, you just want to write some html/js/css and test it. Well this blog is for you. I have two simple options for serving content.
Imagine a world where
serve . results in:
Http Server running at http://localhost:8000/
Its as easy as:
- Install node.js.
- Download web-server.js
- Copy web-server.js to some path (I put mine in /user/local/bin)
alias serve='node /usr/local/bin/web-server.js'
- Restart bash/terminal.
- Navigate to the directory you want to host and type
Now since I love python, it comes installed on Mac.. a better less cool alternative is:
python -m SimpleHTTPServer ...
To take it one step further:
alias serve='python -m SimpleHTTPServer'
- Restart terminal/bash
Hopefully that last step felt a little familiar...
Same exact result, but I created mine first!