Forum OpenACS Q&A: ns_register_proc glob not working

Collapse
Posted by Jonathan Ellis on
I want to story my scripts in a directory off of my pageroot so I can keep them separate from aD's stuff. This will make moving a new set of scripts from my development to production server much simpler. But, I want my scripts to appear to the user as if they're in the root directory. I think that looks more professional. To keep things simple, the directory they will actually be in must be given the value of [ns_info server].

This proc does get registered for /, but NOTHING ELSE. Not /foo.tcl, not /.tcl, not anything. It totally baffles me. I've tried it both with -noinhert on and off, in case noinherit was confusing the globbing. No change. I even tried registering the proc for /*, and STILL couldn't get it to work. (It did screw up a request for a gif on the page, but not for the jpgs; go figure.) I must be doing something really stupid but I'm not sure what.

as usual the bboard is probably going to screw up my backslashes but that shouldn't affect things. (I'm not backslashing anything but part of the util_memoize call.)
ns_register_proc -noinherit GET /*.tcl serve_from_virtualroot ns_register_proc -noinherit POST /*.tcl serve_from_virtualroot ns_register_proc -noinherit GET / serve_from_virtualroot ns_register_proc -noinherit POST / serve_from_virtualroot ns_log Notice "server will first look for /*.tcl in /[ns_info server]" proc serve_from_virtualroot { } { ns_log Notice serve_from_virtualroot set file [util_memoize "get_file_or_virtual_file {[ns_conn url] }"] if [empty_string_p $file] { ns_return 404 text/plain "File not found" } else { source $file } } proc_doc get_file_or_virtual_file { url } { if a file corresponding to the requested url exists in the directory called $server, return that; else return the file from the pageroot } { # special case index if { [string compare $url /] == 0 } { set url /index.tcl } # we assume we are only called by the registered proc # so url will have the form /foo.tcl # we want to trim the / set filename [string range $url 1 end] # check for existence in $server set virtual_file_and_path [file join [ns_info pageroot] [ns_info server] $f$ ns_log Notice "looking for $virtual_file_and_path" if [file exists $virtual_file_and_path] { ns_log Notice "found $virtual_file_and_path" return $virtual_file_and_path } ns_log Notice "looking for $file_and_path" # check for existence in $pageroot set file_and_path [file join [ns_info pageroot] $filename] if [file exists $file_and_path] { return $file_and_path } # not found return "" }