Skip to content

Commit

Permalink
Implement aspen.serve
Browse files Browse the repository at this point in the history
Makes the quickstart quicker; closes #441.
  • Loading branch information
chadwhitacre committed Jun 18, 2015
1 parent dd6aa03 commit de8d15a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 13 additions & 1 deletion aspen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@
from aspen.http.response import Response
from aspen import json_ as json
from aspen.logging import log, log_dammit
from aspen.website import Website

# Shut up, PyFlakes. I know I'm addicted to you.
Response, json, is_callable, log, log_dammit
Response, json, is_callable, log, log_dammit, Website

dist = pkg_resources.get_distribution('aspen')
__version__ = dist.version
Expand All @@ -92,3 +93,14 @@

RENDERERS.sort()


def serve(website, host=None, port=None):
"""Serve a website.
"""
import os
from wsgiref.simple_server import make_server

port = int(os.environ.get('PORT', '8080'))
server = make_server('0.0.0.0', port, website)
log_dammit("Greetings, program! Welcome to port {0}.".format(port))
server.serve_forever()
11 changes: 2 additions & 9 deletions aspen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
from __future__ import print_function
from __future__ import unicode_literals

import os
from aspen import log_dammit
from aspen.website import Website
from wsgiref.simple_server import make_server

from aspen import serve, Website

if __name__ == '__main__':
website = Website()
port = int(os.environ.get('PORT', '8080'))
server = make_server('0.0.0.0', port, website)
log_dammit("Greetings, program! Welcome to port {0}.".format(port))
server.serve_forever()
serve(website)

0 comments on commit de8d15a

Please sign in to comment.