Commits

Greg Slepak committed 7ec03af

- new routing capbility, supports static dir layouts, see STATIC_INDEX_EXTENSION in config.lsp
- windows support
- added TROUBLESHOOTING
- fixed a bug with content-type not being properly sent for static pages

  • Participants
  • Parent commits 94d4436

Comments (0)

Files changed (9)

 \.log$
 \.DS_Store$
-lib/_config\.lsp$
+plugins-active/_config\.lsp$

File TROUBLESHOOTING

+This document addresses problems getting Dragonfly up and running
+in various environments, currently two: newlisp as server, and Apache.
+
++=================+
+ NEWLISP AS SERVER
++=================+
+
+------------------------------------------------------------
+Problem
+ERR:500 Need \tmp directory on current drive: index.cgi
+
+:: Solution ::
+This happens on Windows. newlisp needs a "tmp" folder in C:.
+Just create it here so that it's here: C:\tmp
+
+------------------------------------------------------------
+Problem
+ERR:404 File or Directory not found: index.html
+
+Solution
+Make sure you're running the newlisp command from within
+the 'example-site' directory, or whatever contains your
+'index.cgi' file. This is the command to run:
+
+	newlisp -w . -http -d 8080
+
++=================+
+ APACHE AS SERVER 
++=================+
+
+------------------------------------------------------------
+Problem
+500 Internal Server Error
+
+Solution
+See example in README to check and make sure that the
+path to newlisp is set correctly in index.cgi.
+
+------------------------------------------------------------
+Problem
+index.cgi is not being run.
+
+Solution
+Try adding this to your .htaccess file at the site root:
+
+	AddHandler cgi-script .cgi
+	

File example-site/dragonfly-framework/config.lsp

 (constant (global 'DRAGONFLY_ROOT) (string DOCUMENT_ROOT "/dragonfly-framework"))
 
 ; sync any customization of DOCUMENT_ROOT with the 'env'
-; don't modify these two lines
+; don't modify these two lines below!
 (constant (global 'ORIGINAL_ROOT) (env "DOCUMENT_ROOT"))
 (env "DOCUMENT_ROOT" DOCUMENT_ROOT)
 
 (constant 'ENABLE_STATIC_TEMPLATES true)
 ; file extensions that triggers the handler (update .htaccess to match this!)
 (constant 'STATIC_EXTENSIONS '(".html"))
+; alternatively the static handler can be used to load index files given
+; a URL pointing to a directory. This variable customizes the extension
+; of the index file that the handler will check to see if it handles the request
+; ex: mysite.com/myproduct/support => mysite.com/myproduct/support/index.html
+(constant 'STATIC_INDEX_EXTENSION ".html")
 
 ;===============================================================================
 ; Views

File example-site/dragonfly-framework/dragonfly.lsp

 ; so that things like log-err can be written DF:log-err
 (constant (global 'DF) Dragonfly)
 
+; make sure these two are defined
+(if-not DOCUMENT_ROOT (throw-error "Environment variable DOCUMENT_ROOT missing!"))
+(unless QUERY_STRING
+	(constant (global 'QUERY_STRING) "")
+	(env "QUERY_STRING" QUERY_STRING)
+)
+
 (context 'Dragonfly)
 
 ;===============================================================================
 ; that you might need to clear the default routes out of it (added below)
 (define dragonfly-routes '())
 
-; make sure these two are defined
-(if-not DOCUMENT_ROOT (throw-error "Environment variable DOCUMENT_ROOT missing!"))
-(if-not QUERY_STRING (throw-error "Environment variable QUERY_STRING missing!"))
-
 ;===============================================================================
 ; !Load Libraries and Plugins
 ;===============================================================================
 	((matches?)
 		; ex: .html or .html?a=4
 		(set 'file (if (empty? (set 'chunks (parse QUERY_STRING "?"))) QUERY_STRING (first chunks)))
-		(set 'ext (exists (curry ends-with file) DF:STATIC_EXTENSIONS))
+		(unless (set 'ext (exists (curry ends-with file) DF:STATIC_EXTENSIONS))
+			; alternatively 'file' could actually be a directory, in which case
+			; we need to check if there's an index file in it
+			(set 'ext DF:STATIC_INDEX_EXTENSION)
+			(set 'file (string DOCUMENT_ROOT "/" file "/index" ext))
+			(file? file)
+		)
 	)
 	((run)
 		; pass through template TODO: make sure this is secure! no ../ bullshit!
-		(DF:log-debug "Route.Static: " file)
+		(DF:log-debug (context) ": " file)
 		(Response:content-type (Response:extension->type ext))
 		(unless (Web:eval-template (read-file file))
 			(DF:display-error 404)
 	)
 	((run)
 		; pass through template
-		(DF:log-debug "Route.View: " DF:viewname)
+		(DF:log-debug (context) ": " DF:viewname)
 		(DF:display-view DF:viewname)
 	)
 )

File example-site/dragonfly-framework/lib/request.lsp

 ; !$POST/$FILES/$BINARY
 ;===============================================================================
 
-(unless (zero? (peek (device)))
+; windows doesn't have 'peek'
+;(unless (zero? (peek (device)))
 	(if (and (setf temp HTTP_CONTENT_TRANSFER_ENCODING) (= temp "binary"))
 		(handle-binary-data)
 		(and (setf temp CONTENT_TYPE) (starts-with temp "multipart/form-data"))
 		(dolist (pair (parse-query temp))
 			($POST (first pair) (last pair))
 		)
-		(DF:log-err "couldn't get POST info!")
 	)
-)
+;)
 
 ;===============================================================================
 ; !$COOKIES

File example-site/dragonfly-framework/lib/response.lsp

 
 (define (extension->type file-extension)
 	(if-not (starts-with file-extension ".") (push "." file-extension))
-	(lookup file-extension extension-to-type-map)
+	(eval (lookup file-extension extension-to-type-map))
 )
 
 (constant

File example-site/dragonfly-framework/lib/web.lsp

 (define OPEN_TAG "<%")
 (define CLOSE_TAG "%>")
 
-(define (eval-template str (ctx Dragonfly) , start end next-start next-end block (buf ""))
+(define (eval-template str (ctx Dragonfly) , start end block (buf ""))
 	(while (and (setf start (find OPEN_TAG str)) (setf end (find CLOSE_TAG str)))
 		(write-buffer buf (string "(print [text]" (slice str 0 start) "[/text])"))
 		(setf block (slice str (+ start 2) (- end start 2)))

File example-site/foo/index.html

+<% (display-partial "doctype") %>
+<% (display-partial "header") %>
+
+<body>
+
+<div id="wrap">
+	<div id="header">
+		<% (display-partial "navigation") %>	
+		<div class="clear"></div>
+	</div>
+
+	<div id="content">
+				
+		<div class="title nomargin">
+			<p>Dragonfly web framework<p>
+		</div>
+		<h1>Welcome to a Dragonfly test page!</h1>
+		<p>
+			Here we're testing what happens when you point the browser
+			to a URL like <b>http://mysite.com/foo</b>!
+		</p>
+		<div class="line-dotted"></div>
+
+		<% (benchmark-result) %>
+
+		<div class="line-dotted"></div>
+
+
+	</div><!-- END CONTENT -->
+
+</div><!-- END WRAP -->
+<% (display-partial "footer") %>
+

File example-site/views/500

 	<style type="text/css">
 		body { background-color: #ffffff; color: #666; text-align: center; font-family: arial, sans-serif; }
 		div.dialog {
-			width: 25em;
-			padding: 0 4em;
+			width: 500px;
+			padding: 5px 20px 20px 20px;
 			margin: 4em auto 0 auto;
 			border: 1px solid #00aeef;
 			border-right-color: #00aeef;
 			border-bottom-color: #00aeef;
 		}
+		div.backtrace {
+			font-size: 9pt;
+			font-family: "Courier New", Courier, mono;
+			text-align: left;
+		}
 		h1 { font-size: 100%; color: #333333; line-height: 1.5em; }
 	</style>
 </head>
   <div class="dialog">
     <h1>We're sorry, but something went wrong.</h1>
     <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+	<div class="backtrace">
+		<%=(join (parse (last (last-error)) "\n") "<br/>")%>
+	</div>
   </div>
 </body>
 </html>