How to set up a minimal wub that serves static web pages from "/"

26 views
Skip to first unread message

mb

unread,
Apr 19, 2011, 1:25:50 PM4/19/11
to Wub Discussion
I found a bunch of wub examples on the wubwikit site (linked to from
the wub wiki page).

http://code.google.com/p/wubwikit/downloads/list Follow that link and
download either eurotcl2009-examples.zip

I downloaded those examples but none of them work. I believe it's
because of the changes that have been made to the way Config works.

Is there an easy way to mimic example #1.

--------------- ex.tcl ----- from ex1 directory ---------
lappend auto_path ../Wub ../tcllib/modules .

package require Site

Site start home .
-------------------

There is a docroot under the current directory that contains html
files.
I think if this example worked, I'd be able to navigate to
http://localhost:8080/html/ex.html


What is the new process for setting up this minimal configuration if I
have a docroot filled with static .html files, and i want those files
mounted at / (http://localhost:8080/)?


I tried creating the following Application.tcl

-----------Application.tcl -----------------------
#! /usr/bin/env tclsh

## My Application needs to know how to find Site.tcl.
lappend auto_path [file join [file dirname [info script]] ../Wub]
package require Site

Site start home .

------ end Application.tcl -------------------

and the following Site.config

---------------site.config -----------------------
Wub {
globaldocroot 1; # do we use Wub's docroot, or caller's
docroot [file join [file dirname [info script]] docroot]; #
essentially ./docroot
}

/ {
domain File
root $Wub::docroot
}

default {
url default
code {set r [Http NotFound $r]; <p> "[dict get $r -uri] Not
Found... [clock format [clock seconds]]"}
}
------------------ end site.config -------------------


when I navigation to "/", I keep getting the 'not found' response from
default.



I am able to get static pages served up if I set up a file File domain
on something besides "/"

for instance,

/myApp/ {
domain File
root $Wub::docroot
}

will work if I navigate to
http://localhost:8080/myApp/


Just curious if I'm doing something obviously wrong, or if you just
aren't allowed to hang a File domain off of "/".

Thanks in advance for any advice.

MB

mb

unread,
Apr 29, 2011, 2:22:35 PM4/29/11
to Wub Discussion
I think I found my own answer.

>## the special URL 'default' determines Wub's behavior
>## when a URL can't be resolved
> default {
>     url default
>     code {set r [Http NotFound $r]; <p> "[dict get $r -uri] Not Found... [clock format [clock seconds]]"}
> }
>


There is a conflict when using both "/" and "default".
the default handler seems to always win.

I think the minimal amount of code to set a basic web server to set up
static pages is the following.
it assumes an Application.tcl, site.config file and a docroot
directory in a directory that is a sibling of wub.


----------- Application.tcl ------------------------

set script_dir [file normalize [file dirname [info script]]]
lappend auto_path [file normalize [file join $script_dir .. wub Wub]]

package require Site
Site init config [file join $script_dir site.config]

Site start

---------end -- Application.tcl ------------------------

and a site.config file

---------- site.config -------------------------------------

/ {
domain File
### info script returns the "main" script. (Application.tcl)
root [file normalize [file join [file dirname [info script]]
docroot]]
}
----------------- end site.config -------------------------

mcccol

unread,
Apr 29, 2011, 11:36:18 PM4/29/11
to wub-dis...@googlegroups.com


On Saturday, 30 April 2011 04:22:35 UTC+10, mb wrote:

I think the minimal amount of code to set a basic web server to set up
static pages is the following.
it assumes an Application.tcl, site.config file and a docroot
directory in a directory that is a sibling of wub.

Try dispensing with Application.tcl and just starting the server by running Site.tcl ... I think that should work, as Site.tcl's default behaviour when run as a command is roughly what you outline in your example Application.tcl.  If it doesn't work that way, it should, and I'll modify it to suit.

Come to think of it, I probably ought to rename Site.tcl to Wub.tcl.

Colin


Reply all
Reply to author
Forward
0 new messages