Permalink
Browse files

Serve favicon.ico in web examples

  • Loading branch information...
birchb1024 committed Mar 25, 2018
1 parent 2313303 commit d8bd191c174d53bcc9f98d0a1e9ab764690c95b3
@@ -1,4 +1,19 @@
@prefix sys "http://www.genyris.org/lang/system#"
define script
(File(.new @FILE))
.abs-path
define script-dir
"The same as (script(.dirname))"
'/'
.join
reverse
right
reverse
script (.split '/')
define context (dict)
def myparse (string)
# parse a string returning the expression
@@ -8,9 +23,10 @@ def myparse (string)
.read
df httpd-serve (request)
print request
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
define expression nil
define expression-string ''
BIN +3.96 KB examples/favicon.ico
Binary file not shown.
@@ -2,17 +2,29 @@
@prefix task "http://www.genyris.org/lang/task#"
@prefix u "http://www.genyris.org/lang/utilities#"
define script
(File(.new @FILE))
.abs-path
define script-dir
'/'
.join
reverse
right
reverse
script (.split '/')
df httpd-serve (request)
# print request
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
list 200 "text/html"
template
html()
head()
title() $script
body()
div()
"username: foo"
@@ -27,7 +39,7 @@ def web-tasks()
li()
a
(href = $("http://127.0.0.1:%a/"(.format (must-split x!name 1))))
$(must-split x!name 2)
$(must-split x!name 2) ' ' $(must-split x!name 1)
def must-split (item index)
@@ -40,14 +52,15 @@ def must-split (item index)
cond
(equal? (task:id)!name 'main')
httpd 8000 @FILE
httpd 8001 'examples/www-demo.g'
httpd 8002 'examples/www-basic-auth.g'
httpd 8003 'examples/www-hello.g'
httpd 8004 'examples/www-ntlm.g'
httpd 8005 'examples/www-rcepl.g'
httpd 8006 'examples/www-static.g'
httpd 8007 'examples/web-server.g' '8007' 'examples'
httpd 8008 'examples/apps/inspector/inspect.g'
for count in (range 1 1)
httpd 8000 @FILE
httpd 8001 'examples/www-demo.g'
httpd 8002 'examples/www-basic-auth.g'
httpd 8003 'examples/www-hello.g'
httpd 8004 'examples/www-ntlm.g'
httpd 8005 'examples/www-rcepl.g'
httpd 8007 'examples/web-server.g' '8007' 'examples'
httpd 8008 'examples/apps/inspector/inspect.g'
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
while true
sleep (* 60 60 1000)
@@ -2,6 +2,19 @@
@prefix u "http://www.genyris.org/lang/utilities#"
@prefix task "http://www.genyris.org/lang/task#"
define script
(File(.new @FILE))
.abs-path
define script-dir
"The same as (script(.dirname))"
'/'
.join
reverse
right
reverse
script (.split '/')
def valid-logon?(username password)
# redefine to suit
(and (equal? username 'foo') (equal? password 'bar'))
@@ -15,13 +28,17 @@ def authenticate(request)
df httpd-serve (request)
# Serve web page, catch an errors and report with backtrace.
var response nil
catch errors
setq response (raw-serve request)
cond
(not errors) response
else
backtrace request errors
cond
(equal? (request(.getPath)) '/favicon.ico')
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
var response nil
catch errors
setq response (raw-serve request)
cond
(not errors) response
else
backtrace request errors
def backtrace (request errors)
# Error page
@@ -5,12 +5,21 @@
define script
(File(.new @FILE))
.abs-path
define script-dir
"The same as (script(.dirname))"
'/'
.join
reverse
right
reverse
script (.split '/')
define counter 0
df httpd-serve (request)
print request
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
setq counter (+ counter 1)
list 200 "text/html"
@@ -2,15 +2,32 @@
@prefix task "http://www.genyris.org/lang/task#"
@prefix u "http://www.genyris.org/lang/utilities#"
define script
(File(.new @FILE))
.abs-path
define script-dir
"The same as (script(.dirname))"
'/'
.join
reverse
right
reverse
script (.split '/')
df httpd-serve (request)
print request
list 200 "text/html"
template
html()
head()
body()
h1()
"Hello World"
cond
(equal? (request(.getPath)) '/favicon.ico')
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
list 200 "text/html"
template
html()
head()
body()
h1()
"Hello World"
cond
(equal? (task:id)!name 'main')
httpd 8000 @FILE
@@ -4,6 +4,20 @@
include 'classify.g'
define script
(File(.new @FILE))
.abs-path
define script-dir
"The same as (script(.dirname))"
'/'
.join
reverse
right
reverse
script (.split '/')
class ListOfInts()
defmethod .beginsWith?(other)
beginsWith? other this
@@ -140,7 +154,11 @@ class NtlmAuthorizationType3(NtlmAuthorizationInts)
df httpd-serve (request)
request
cond
(equal? (request(.getPath)) '/favicon.ico')
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
request
print .self
classify UncheckedRequest .self
define response (.reply)
@@ -11,6 +11,18 @@ include "lib/classify.g"
include "examples/people.g"
define script
(File(.new @FILE))
.abs-path
define script-dir
'/'
.join
reverse
right
reverse
script (.split '/')
Bignum
def .new(obj)
define parser (ParenParser(.new obj))
@@ -103,38 +115,42 @@ df httpd-serve (request)
err
setq expression err
list 200 "text/html"
template
html()
head()
title() $sys:argv
style()
verbatim() "table, th, td { padding: 10px; border: 1px solid black; border-collapse: collapse; }"
body()
div()
form((action="posted") (method="post"))
fieldset()
legend()
"Read-Eval-Classify-Render Form:"
textarea
(rows="10")
cols="50"
name="recr"
wrap="physical"
~$input_line
br()
input((type="submit")(name="Submit")(value="submit"))
div()
'Classes: '
ul()
$(map-left (use expression .classes) StandardClass!render:html)
div()
pre()
$(asString expression)
fieldset()
legend()
"Render as HTML:"
$(catch err (expression(.render:html)))
cond
(equal? (request(.getPath)) '/favicon.ico')
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
else
list 200 "text/html"
template
html()
head()
title() $sys:argv
style()
verbatim() "table, th, td { padding: 10px; border: 1px solid black; border-collapse: collapse; }"
body()
div()
form((action="posted") (method="post"))
fieldset()
legend()
"Read-Eval-Classify-Render Form:"
textarea
(rows="10")
cols="50"
name="recr"
wrap="physical"
~$input_line
br()
input((type="submit")(name="Submit")(value="submit"))
div()
'Classes: '
ul()
$(map-left (use expression .classes) StandardClass!render:html)
div()
pre()
$(asString expression)
fieldset()
legend()
"Render as HTML:"
$(catch err (expression(.render:html)))
cond
@@ -9,6 +9,19 @@
include 'examples/www-basic-auth.g'
define script
(File(.new @FILE))
.abs-path
define script-dir
'/'
.join
reverse
right
reverse
script (.split '/')
var *users* (graph)
*users*
.add
@@ -26,7 +39,7 @@ def valid-logon?(username password)
def handle-authenticated-request (request username)
list ^SERVE-FILE '/' (request(.getPath)) ^ls
list ^SERVE-FILE script-dir (request(.getPath)) ^ls
cond

0 comments on commit d8bd191

Please sign in to comment.