Project

General

Profile

Actions

Feature #3404

open

docRoot per URL

Added by Jeff Flesher over 9 years ago. Updated over 9 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
06/30/2014
Due date:
% Done:

0%

Estimated time:

Description

Currently docRoot is defined at run time via ---docRoot, but for Applications with Multiple URL that want to access a different docRoot based on the URL, this approach does not work.

Running an Application per URL also does not work on my VPS, I run out of PostgreSQL connections too fast, also this is just not a very efficient approach, in my Opinion this fix is easy to make without causing any backwards compatibility issues, and does not take much time to execute, so its well worth the Feature.

Modifying WApplication.C docRoot as Below code blocked worked to fix the problem with docRoot, but would need to be fixed in Configuration.C, or what ever code sets appDoc.

The idea is simple, in wt_config.xml, set a property for a custom docRoot as such:

    <property name="customDocRoot-localhost">/path/doc_root/</property> 
    <property name="customDocRoot-domain.tdl">/path/doc_root/</property>

If the name does not exist, it will return the value the old way.

std::string WApplication::docRoot() const
{
    // define Custom docRoot
    std::string myCDR;
    // Get host Name
    WApplication *app = WApplication::instance();
    std::string domainName = app->environment().hostName().c_str();
    // Remove Port number if it exist
    unsigned pos = domainName.find(":");
    if (pos > 0)
      domainName = domainName.substr(0, pos);
    // Now do a look up in wt_config: <property name="customDocRoot-domain.tdl">/path/doc_root/</property>
    if (!readConfigurationProperty("customDocRoot-" + domainName, myCDR))
       Wt::log("warning") << "WApplication::docRoot() readConfigurationProperty not found in wt_config.xml for: customDocRoot-" << domainName << ". Add <property name=\"customDocRoot-" << domainName << "\">/path/doc_root</property>";
    if (myCDR.empty())
      return environment().getCgiValue("DOCUMENT_ROOT");
    else
      return myCDR.c_str();
}

You could do the same thing for appRoot, that way it would not have to be hard coded.

Jeff Flesher

Thanks

Actions #1

Updated by Jeff Flesher over 9 years ago

After much thought, the real issue is the base path, if you could change the base path, the names of the docRoot, appRoot or resource would be fine, it seems it gets its base path from the executable, it seems this would be easy enough to change if you know the library, for now I need to research how to do this to make any suggestions, does anyone know where the code is that sets the base path, i.e. the path that docRoot, appRoot or resource gets its full path to resolve from?

Example:

I want to deploy the app in /usr/bin/App.wt, and have docRoot, appRoot or resource in /home/domainName, based on the URL, so if the URL is domain.tdl, its /home/domain.tdl

Thanks.

Actions

Also available in: Atom PDF