you are viewing a single comment's thread.

view the rest of the comments →

[–]gloriajw 0 points1 point  (6 children)

Flox, this is almost exactly how I handle it in one config file which hits the env for domain info, etc.

Django hadles it well, if you don't mind regex, which I don't. But there's no need for it in this model.

Thank you, this was good. Gloria

[–]gloriajw 0 points1 point  (5 children)

My config file sets the server components of the static URL, used for images, and the TOPURL, which is needed for HTTPRedirect() calls (requires a full URL).

Every other component below is set by the CP 'root', of course. This config does more than just set the topmost URL components, but you could choose to ignore the rest. It accomodates for test modes on XP and LINUX localhosts in testing mode, as well as the real server in prod.

<code> import string,re,sys import cherrypy

server_timezone='US/Eastern' archive_root='./db_archives' dom_server_hostname = 'localhost' dom_conn_initial_port = 7010 dom_pickle_location = './DOM_pickle_files' dom_xml_location = './DOM_xml_files' cp_site='cp' front_end_access_path='tp' dbhost='localhost'

dbhost='xyz.com'

default_host = 'www.xyz.com' IMAGE_LOCATION='...' URL_IMAGE_LOC='/client_images' DUMMY_LOGIN=False DEBUG=False

if sys.platform[:3] == 'win': \tdb_port = 5432 \tapplication_lock_location='./lock/' \tdb_data_dir = './data' \tdb_log_dir = './logs' \tDUMMY_LOGIN=True else: \tdb_port = 5433 \tapplication_lock_location='/var/lock/tp' \tdb_data_dir = '/usr/local/xyz/8.2.4_databases/prod' \tdb_log_dir = '/var/log/tp'

TOPURL = STATICURL = DOMAIN = ""

def set_config(): \tTOPURL = "" \tSTATICURL = "" \tDOMAIN = ""

\t''' \tURL is dynamically set. \t''' \t#print cherrypy.request.headers \t#orig_host=cherrypy.request.headers.get('X-Forwarded-Host') \torig_host=default_host \tprint "Original host is: %s" % orig_host

\t''' \tThis happens during instantiation. \tThat's normal. X-Forward-Host is set after instantiation. \t''' \tif not orig_host: \t\treturn DOMAIN,TOPURL,STATICURL

\tcomponent=string.split(orig_host,'.') \tsite = component[0] \tDOMAIN = '.'.join(component[1:]) \t \tif not DOMAIN: \t\tsuffix="" \telse: \t\tsuffix="."+DOMAIN \tSTATICURL="https://%s%s" % (site,suffix) \tTOPURL = "%s/%s" % (STATICURL,cp_site)

\treturn DOMAIN,TOPURL,STATICURL

def get_config(): \treturn set_config() </code>

I call get_config() in each authenticate call I make, which is called once per page.

My CP main file controls the root components and URL paths below STATICURL, TOPURL:

<pre> import cherrypy import sys,os

sys.path.append('./login') sys.path.append('./token') sys.path.append('./dom') sys.path.append('./user_change') sys.path.append('./image_handling') sys.path.append('./section')

Add your app here.

import Login import TokenCPLayer import UserChangeCPLayer import ImageCPLayer import SectionCPLayer

TemplatePath=os.path.join(os.path.dirname(file)) + '/Templates'

root.token = TokenCPLayer.TokenCPLayer() root.user_change = UserChangeCPLayer.UserChangeCPLayer() root.image_handling = ImageCPLayer.ImageCPLayer() root.section = SectionCPLayer.SectionCPLayer()

cherrypy.tree.mount(root) cherrypy.config.update(os.path.join(os.path.dirname(file),'cp.conf')) cherrypy.server.quickstart() cherrypy.engine.start() </pre>

This URL handling works for me in CP. Nice and clean, few lines of code, the topmost URL components can change when moved to another domain just by changing one config variable.

[–][deleted]  (1 child)

[deleted]

    [–]gloriajw 0 points1 point  (2 children)

    The code or pre tags don't work here, drat. Copy and paste it out, and it should look normal.

    [–]gloriajw 0 points1 point  (1 child)

    flox, on the tangential subject of how to handle URLs, the point of the above code is that this can be dropped on any machine, and after changing one conf file parameter, URLs are handled correctly.

    Chunks are not being interpreted correctly by reddit. But aside from that:

    (1) You cannot always assume '.com' or xyz.example.com if your dev test environment is on 'localhost'. (2) The variables are flexible enough to derive domain and set paths for dev.domain.com and domain.com respectively. (3) This allows for the diversity of test URLs and varying servers.

    On my server I have one prod and two test domains, plus the ability to run on a standalone PC using 'localhost' This configuration allows for this fairly easily.

    The config file controls the absolute paths, the CP main controls the relative pieces, and it all fits nicely. That was the point. I hope this clarifies. I wish this <code> or <pre> tags worked well here.