Skip to content

Commit

Permalink
fixed craft serve
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Feb 7, 2021
1 parent 946f2bf commit 4cc3453
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/masonite/wsgi.py
Expand Up @@ -46,3 +46,52 @@ def response_handler(environ, start_response):
it to the WSGI server.
"""
return iter([response.get_response_content()])

def package_response_handler(environ, start_response):
"""The WSGI Application Server.
Arguments:
environ {dict} -- The WSGI environ dictionary
start_response {WSGI callable}
Returns:
WSGI Response
"""
from wsgi import container

"""Add Environ To Service Container
Add the environ to the service container. The environ is generated by the
the WSGI server above and used by a service provider to manipulate the
incoming requests
"""

container.bind("Environ", environ)

"""Execute All Service Providers That Require The WSGI Server
Run all service provider boot methods if the wsgi attribute is true.
"""

try:
for provider in container.make("WSGIProviders"):
container.resolve(provider.boot)
except Exception as e:
container.make("ExceptionHandler").load_exception(e)

"""We Are Ready For Launch
If we have a solid response and not redirecting then we need to return
a 200 status code along with the data. If we don't, then we'll have
to return a 302 redirection to where ever the user would like go
to next.
"""

from src.masonite.response import Response

response = container.make(Response)

start_response(response.get_status_code(), response.get_and_reset_headers())

"""Final Step
This will take the data variable from the Service Container and return
it to the WSGI server.
"""
return iter([response.get_response_content()])
4 changes: 2 additions & 2 deletions wsgi.py
Expand Up @@ -2,7 +2,7 @@

from src.masonite.app import App

from src.masonite.wsgi import response_handler
from src.masonite.wsgi import response_handler, package_response_handler
from src.masonite.helpers import config
from src.masonite.environment import LoadEnvironment

Expand All @@ -15,7 +15,7 @@

container = App()

container.bind('WSGI', response_handler)
container.bind('WSGI', package_response_handler)
container.bind('Container', container)

container.bind('Providers', [])
Expand Down

0 comments on commit 4cc3453

Please sign in to comment.