Skip to content

Commit

Permalink
Merge pull request #500 from MasoniteFramework/feature/499
Browse files Browse the repository at this point in the history
added back subdomain activation
  • Loading branch information
josephmancuso authored Jan 20, 2022
2 parents ceeb680 + dfdd476 commit 35fd2e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/masonite/api/providers/ApiProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from ...routes import Route
from ...utils.structures import load
import os


class ApiProvider(Provider):
Expand Down
3 changes: 3 additions & 0 deletions src/masonite/providers/FrameworkProvider.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from email.mime import application
from ..foundation import response_handler
from ..request import Request
from ..response import Response
Expand All @@ -14,6 +15,8 @@ def register(self):
def boot(self):
request = Request(self.application.make("environ"))
request.app = self.application
if self.application.has('activate.subdomains') and self.application.make('activate.subdomains'):
request.activate_subdomains()
self.application.bind("request", request)
self.application.bind("response", Response(self.application))
self.application.bind("start_time", time.time())
8 changes: 8 additions & 0 deletions src/masonite/request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, environ):
self.input_bag = InputBag()
self.params = {}
self._user = None
self._subdomains_activated = False
self.load()

def load(self):
Expand Down Expand Up @@ -128,6 +129,9 @@ def contains(self, route):
return regex.match(self.get_path())

def get_subdomain(self, exclude_www=True):
if not self._subdomains_activated:
return None

url = tldextract.extract(self.get_host())
if url.subdomain == "" or (
url.subdomain and exclude_www and url.subdomain == "www"
Expand All @@ -138,3 +142,7 @@ def get_subdomain(self, exclude_www=True):

def get_host(self):
return self.environ.get("HTTP_HOST")

def activate_subdomains(self):
self._subdomains_activated = True
return self

0 comments on commit 35fd2e1

Please sign in to comment.