BlackSheep icon indicating copy to clipboard operation
BlackSheep copied to clipboard

Multitenant Application

Open yasirakel opened this issue 2 years ago • 1 comments

Hi,

Are you using it in frappe framework before? It allows multiple sites to work through a single application. The settings file for each site is stored with json and run with the following code. Is it possible to configure the global settings according to the site name by checking the request header for BlackSheep? If possible how can I configure the request header for the application.

`def init_request(request): frappe.local.request = request frappe.local.is_ajax = frappe.get_request_header("X-Requested-With")=="XMLHttpRequest"

site = _site or request.headers.get('X-Frappe-Site-Name') or get_site_name(request.host)
frappe.init(site=site, sites_path=_sites_path)

if not (frappe.local.conf and frappe.local.conf.db_name):
	# site does not exist
	raise NotFound

if frappe.local.conf.get('maintenance_mode'):
	frappe.connect()
	raise frappe.SessionStopped('Session Stopped')
else:
	frappe.connect(set_admin_as_user=False)

request.max_content_length = frappe.local.conf.get('max_file_size') or 10 * 1024 * 1024

make_form_dict(request)

if request.method != "OPTIONS":
	frappe.local.http_request = frappe.auth.HTTPRequest()`

Thanks

yasirakel avatar Mar 16 '22 17:03 yasirakel

Hi @yasirakel I am not familiar with frappe. The closest thing that is supported in BlackSheep are mounts: https://www.neoteroi.dev/blacksheep/mounting/

To read headers, for example:

@app.router.get("/")
def home(request):
    accept = request.headers[b"Accept"]
    accept = request.headers.get_first(b"Accept")
    ...

RobertoPrevato avatar Mar 17 '22 19:03 RobertoPrevato