Skip to content
/ server Public

A small server script to host content in a directory, with some extras

License

Notifications You must be signed in to change notification settings

rnelson/server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

server

Sometimes, you just need to serve some static content from a directory. When that happens, python -m SimpleHTTPServer or php -S is pretty handy, but what if you want a little more?

This script will handle all of those, but it will also allow you to minify LESS/SASS/SCSS and run Python scripts.

Installation

server.py requires a recent version of Python 3.

  1. Install the dependencies: python -m pip install -r requirements.txt (may require doas or sudo)
  2. Clone the repo: git clone https://github.com/rnelson/server.git
  3. Create a symlink: ln -s /path/to/server/server.py ~/bin/server

Usage

Whatever directory you are in when you run the script is the root. This is now available at http://localhost:9000.

For LESS/SASS/SCSS files, give them the appropriate extension (.less, .sass, .scss) and they'll automatically be minified.

The Python script support relies on globals() to pass data from the executing script back to server. Two values are read, output and output_type (the latter defaults to text/html) to determine what to display and how to display it. The following is a trivial example:

#! env python

content = 'Hello, {}!'.format('World')
globals()['output'] = content
globals()['output_type'] = 'text/plain'  # defaults to 'text/html'

License

Released under the MIT License.

About

A small server script to host content in a directory, with some extras

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages