Git Product home page Git Product logo

quickserver's Introduction

What is ... ?

You want a simple web server started in a directory for dev or whatever, so you could use good ol' python -m SimpleHTTPServer but you are busy and you don't care about the port but UGH you have to pick a port and maybe it collides with the server you're already running on 8000? but OMG picking ports is so hard I don't CARE can't someone just do it for me why yes someone can! It's your operating system, if you ask to listen a socket on port 0 then it will assign one for you from its vast array of 16-bit uints. Oh and then of course you don't want to mouse over to the URL and copy/paste it like a peasant so hey, quickserver will open it FOR YOU in your browser thanks you're welcome.

Requirements

  • Python 2.5 or greater. Works with Py3k.

Usage

$ quickserver
Serving HTTP on 0.0.0.0 port 61209 ...
http://0.0.0.0:61209/
127.0.0.1 - - [19/Jun/2014 17:21:56] "GET / HTTP/1.1" 200 -

~ YOUR BROWSER HAS MAGICALLY OPENED A NEW TAB TO THIS URL REJOICE ~

Installation

Put the quickserver file somewhere in your $PATH, or copy/paste this into your .bashrc:

quickserver () {
    prog=quickserver
    f1=/tmp/.$prog.$$.1
    f2=/tmp/.$prog.$$.2
    mkfifo $f1 $f2
    trap "rm -f $f1 $f2" EXIT
    grep --line-buffered -E '^Serving HTTP on .* port .* \.\.\.$' < $f1 | \
        sed -l -E -e 's|Serving HTTP on (.+) port (.+) \.\.\.|http://\1:\2/|' > $f2 &
    {
        read addr <$f2
        echo $addr
        python -m webbrowser -t $addr
    } &
    py2=`python -c 'import sys; print("%i" % (sys.hexversion<0x03000000))'`
    if [ $py2 -eq 0 ]; then
        python -u -m http.server 0 | tee $f1
    else
        python -u -m SimpleHTTPServer 0 | tee $f1
    fi
 }

Copying

Copyright 2014 Paul Smith

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

quickserver's People

Contributors

llimllib avatar paulsmith avatar zephyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zephyr chumpalump

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.