There can be cases where you might need to test the web-pages locally within your source tree and without deploying on web server.
Recently I faced a situation where I have to test my AngularJS App where I am using partials(templates). Partials are loaded through AJAX. If I tried to open the page in browser ,it stops me giving the Cross-Origin exception.
However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!
So cd to your project directory, for instance
- cd /home/erick/mysuperproject and then simply use
- python -m SimpleHTTPServer And that’s it, you’ll see this message in your terminal
- Serving HTTP on 0.0.0.0 port 8000 ... So now you can go back to your browser and visit
http://0.0.0.0:8000with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.
No comments:
Post a Comment