Forum OpenACS Q&A: Re: ns_conn location returning odd location

Collapse
Posted by Raul Rodriguez on
Hi Gustaf,
How do we configure ns_locationproc?

From https://naviserver.sourceforge.io/n/naviserver/files/ns_locationproc.html
We copied the example code into config.tcl:

ns_locationproc   nstest::location arg
 proc nstest::location {args} {
    return "testlocation.$args"
}

and got:

[-main:conf-] Error: no initializing server
no initializing server
    while executing
"ns_locationproc   nstest::location arg"
(context: configuration) line 1044
[-main:conf-] Fatal: error in configuration file /usr/local/ns/config-oacs-5-10-0.tcl line 1044

Thank you for your help

Collapse
Posted by Gustaf Neumann on
Hi Raul,

The error message means that at the time this proc was called, the server was not yet defined. Simply speaking, you called the proc too early.

The configuration file determines several parameters which are applicable for multiple servers, later, the defined servers are initialized (loading modules, etc.). You can see this as well from the prefix used in the error.log.

When one loads this at some later time, - maybe in your OpenACS package nstest - you will see during sourcing a message like

[03/Mar/2023:13:19:38.295950][-main:oacs-5-10-] Notice: SOURCING location-procs.tcl

where "oacs-5-10" is the name of the server. Note that OpenACS has - since ages - several features controlled via package parameters and host-node map to produce its own understanding of the "current location" [1]. So, if you change the lower-level semantics, the likelihood to change some behavior is greater than 0.

The example in the man page is from the NaviServer regression test - so probably not the best. Put this following file e.g. to the "tcl" directory of one of your packages (using for instance the name location-procs.tcl).

namespace eval nstest {
    ns_locationproc ::nstest::location

    ad_proc ::nstest::location {args} {
        set location [ns_conn protocol]://[ns_set iget [ns_conn headers] host]
        ns_log notice "LOCATION-PROC args <$args> - location <$location>"
        return $location
    }
    ns_log notice "SOURCING location-procs.tcl <[ns_info server]>"
}

Hope, this helps.

The main question for me is, why you do not want to stick with the standard behavior.

all the best -g
[1] https://openacs.org/api-doc/proc-view?proc=util_current_location&source_p=1