wapp-default always get run
(1) By Rokas (Rokasg) on 2022-11-14 20:55:37 [link] [source]
I am in the process of coding my own web app with Wapp, and I am enjoying the simplicity of it. However, I've noticed that wapp-default route gets executed every time: If another wapp-page-xxx proc gets run, wapp-default gets run as well. If wapp-default is supposed to run (like in Hello World example here in the docs), wapp-default gets run TWICE. To see that, simply add the line "puts wapp-default-runs" to the wapp-default proc, and run it. It gets printed twice to the console (although, on the other hand, wapp-trim in it don't get run). Why is that? Cheers, Rokas
(2) By D. Richard Hipp (drh) on 2022-11-15 00:04:07 in reply to 1 [link] [source]
I have lots of Wapp scripts in production, and I have never observed this. I think something else is going wrong.
(3) By Rokas (Rokasg) on 2022-11-15 06:41:07 in reply to 2 [link] [source]
Hi Richard,
I've just downloaded fresh "wapp.tcl" from here https://wapp.tcl-lang.org/home/file/wapp.tcl?mimetype=text/plain, copy pasted the Hello World program into "hello.tcl" file placed next to "wapp.tcl", changed "package require wapp" into "source wapp.tcl", added "puts hi" line to the wapp-default proc and run it with "tclsh hello.tcl --server 8080". When I go to localhost:8080, it prints "hi" twice.
I run it this time from WSL. So both linux and windows does it for me.
The hello.tcl file I used:
source wapp.tcl
proc wapp-default {} {
puts "hi"
wapp-subst {<h1>Hello, World!</h1>\n}
}
wapp-start $argv
PS: thanks for Wapp, and SQLite of course.
(4) By D. Richard Hipp (drh) on 2022-11-15 11:21:35 in reply to 3 [link] [source]
I only get one "hi" output here.
What do you see if you insert:
source wapp.tcl proc wapp-default {} { puts "hi" puts [wapp-debug-env] ;#### Added this line wapp-subst {<h1>Hello, World!</h1>\n} } wapp-start $argv
Also, add the --trace command-line option:
tclsh hello.tcl --server 8080 --trace
(5) By Rokas (Rokasg) on 2022-11-15 11:54:53 in reply to 4 [source]
I ran it with --trace, and I get the following with Firefox (so only once):
http://localhost:8080
hi
BASE_URL = http://localhost:8080
DOCUMENT_ROOT = C:/Projects/test
HTTP_ACCEPT_ENCODING = {gzip, deflate, br}
HTTP_HOST = localhost:8080
HTTP_USER_AGENT = {Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0}
PATH_HEAD = {}
PATH_INFO = {}
PATH_TAIL = {}
QUERY_STRING = {}
REMOTE_ADDR = 127.0.0.1
REMOTE_PORT = 53080
REQUEST_METHOD = GET
REQUEST_URI = /
SAME_ORIGIN = 0
SCRIPT_FILENAME = C:/Projects/test/hw.tcl
SCRIPT_NAME = {}
SELF_URL = http://localhost:8080/
WAPP_MODE = server
[pwd] = C:/Projects/test
And this with Edge and Chrome:
http://localhost:8080
hi
BASE_URL = http://localhost:8080
DOCUMENT_ROOT = C:/Projects/test
HTTP_ACCEPT_ENCODING = {gzip, deflate, br}
HTTP_HOST = localhost:8080
HTTP_USER_AGENT = {Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35}
PATH_HEAD = {}
PATH_INFO = {}
PATH_TAIL = {}
QUERY_STRING = {}
REMOTE_ADDR = ::1
REMOTE_PORT = 53300
REQUEST_METHOD = GET
REQUEST_URI = /
SAME_ORIGIN = 0
SCRIPT_FILENAME = C:/Projects/test/hw.tcl
SCRIPT_NAME = {}
SELF_URL = http://localhost:8080/
WAPP_MODE = server
[pwd] = C:/Projects/test
http://localhost:8080/favicon.ico
hi
BASE_URL = http://localhost:8080
DOCUMENT_ROOT = C:/Projects/test
HTTP_ACCEPT_ENCODING = {gzip, deflate, br}
HTTP_HOST = localhost:8080
HTTP_REFERER = http://localhost:8080/
HTTP_USER_AGENT = {Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35}
PATH_HEAD = favicon.ico
PATH_INFO = /favicon.ico
PATH_TAIL = {}
QUERY_STRING = {}
REMOTE_ADDR = ::1
REMOTE_PORT = 53302
REQUEST_METHOD = GET
REQUEST_URI = /favicon.ico
SAME_ORIGIN = 1
SCRIPT_FILENAME = C:/Projects/test/hw.tcl
SCRIPT_NAME = {}
SELF_URL = http://localhost:8080/favicon.ico
WAPP_MODE = server
[pwd] = C:/Projects/test
So it looks like Chrome and Edge always request a favicon.ico, and because I don't have a route for that, the default one gets run.