Commits

Greg Slepak  committed 0924bfc

- new command-event redirection for built-in newLISP server! no longer need to prepend ? when running built-in server
- new command-event handler also handles GET parameters appeneded to the request the way apache QSA redirection does!
- updated multiplication value for newlisp symbol size from 32 to proper 28 value
- removed all use of ? prepending to URLs

  • Participants
  • Parent commits a398644

Comments (0)

Files changed (13)

+Version 0.51
+
+  * added redirection script when running the built-in newLISP server
+  * changed recommendations to run ./newlispServer
+
 Version 0.50
 
   * massive rewrite. too many changes to list, if you want to see them look through the mercurial change log:
 
 'cd' into the example-site folder and run this command:
 
-	newlisp -d 8080 -w . -http
+	./newlispServer
+
+If you're on Windows open that file and run the command that's
+inside of it manually instead, i.e.:
+
+	newlisp "dragonfly-framework/newlisp-redirection.lsp" -c -http -d 8080 -w .
 
 Open Your browser and visit http://localhost:8080/ - have FUN!
 
 For installation information see INSTALL or after running
 the above command visit:
 
-	http://localhost:8080/?dragonfly_welcome
+	http://localhost:8080/dragonfly_welcome
 

File TROUBLESHOOTING

 the 'example-site' directory, or whatever contains your
 'index.cgi' file. This is the command to run:
 
-	newlisp -w . -http -d 8080
+	./newlispServer
+	
+Or, if you're on Windows:
+
+	newlisp "dragonfly-framework/newlisp-redirection.lsp" -c -http -d 8080 -w .
 
 +=================+
  APACHE AS SERVER 

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

 )
 
 ; setup our error handler
-(define (error-handler)
+(error-event (fn ()
 	;(log-err "Got error (" (last (last-error)) ") with STDOUT contents:\n{" STDOUT "}")
 	(log-err (last (last-error)))
 	(display-error 500)
 	(send-and-exit)
-)
-
-(error-event error-handler)
+))
 
 ;===============================================================================
 ; !Private Variables
 <title><%= (join (map string (Response:status)) " ") %></title>
 </head><body>
 <h1><%= (last (Response:status)) %></h1>
-<p>The requested URL <%= (web-root QUERY_STRING (find "newLISP" SERVER_SOFTWARE)) %> resulted in error <%= (join (map string (Response:status)) " ") %>.</p> 
+<p>The requested URL <%= (web-root QUERY_STRING) %> resulted in error <%= (join (map string (Response:status)) " ") %>.</p> 
 <p>Additionally, a 404 Not Found
 error was encountered while trying to use an ErrorDocument to handle the request.</p>
 </body></html>

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

+;; This file is used when testing using the newLISP server
+;; i.e. via the ./newlispServer command
+;; 
+;; This allows you to use URLs like this:
+;; 	http://localhost:8080/dragonfly_welcome
+;; Instead of:
+;; 	http://localhost:8080/?dragonfly_welcome
+
+(set 'NEWLISP_REDIRECTION_EXTRACT_PATH (regex-comp {\w+\s+/([^\s]+)}))
+(set 'NEWLISP_REDIRECTION_REWRITE (regex-comp {^(\w+)\s+/([^\?]+)(\?)?}))
+
+(define (command-event-handler s , request)
+	(regex NEWLISP_REDIRECTION_EXTRACT_PATH s 0x10000)
+	(set 'request $1)
+	(if (and request (not (file? request)))
+		(replace NEWLISP_REDIRECTION_REWRITE s
+			(string $1 " /?" $2 (if $3 "&" "")) 0x10000
+		)
+	)
+	s
+)
+
+(command-event command-event-handler)

File example-site/dragonfly-framework/plugins-active/dragonfly_basic.lsp

   (set 'mem_cells-constant_kilobytes (/ mem_cells-constant_bytes 1024))
   (set 'mem_cells-constant_megabytes (/ mem_cells-constant_kilobytes 1024))
 
-  (set 'mem_symbols_bytes (* (sys-info 2) 32))
+  (set 'mem_symbols_bytes (* (sys-info 2) 28))
   (set 'mem_symbols_kilobytes (/ mem_symbols_bytes 1024))
 
   (set 'mem_total_usage (+ mem_cells_kilobytes mem_symbols_kilobytes))
   (println "
 	<div id='dragonfly_debug'>
 	<h1>Dragonfly DEBUG information</h1><br/>
-	<h2>HOST</h2>" HTTP_HOST "
-	<h2>DOCUMENT ROOT</h2>"DOCUMENT_ROOT"
-	<h2>DRAGONFLY ROOT</h2>"DRAGONFLY_ROOT"
-	<h2>Windows Programfiles</h2>"PROGRAMFILES"
-	<h2>QUERY</h2>"QUERY_STRING"
+	<h2>HTTP_HOST</h2>"HTTP_HOST "
+	<h2>DOCUMENT_ROOT</h2>"DOCUMENT_ROOT"
+	<h2>DRAGONFLY_ROOT</h2>"DRAGONFLY_ROOT"
+	<h2>QUERY_STRING</h2>"QUERY_STRING"
 	<h2>REQUEST METHOD</h2>"REQUEST_METHOD"
-	<h2>DEFAULT VIEW</h2>"DEFAULT_VIEW"
-	<h2>CURRENT VIEW</h2>"viewname"
-	<h2>USER-AGENT</h2>"HTTP_USER_AGENT"
-	<h2>Proxy</h2>"HTTP_PROXY"
-	<h2>SERVER</h2>"SERVER_SOFTWARE"
+	<h2>DEFAULT_VIEW</h2>"DEFAULT_VIEW"
+	<h2>DF:viewname</h2>"viewname"
+	<h2>HTTP_USER_AGENT</h2>"HTTP_USER_AGENT"
+	<h2>HTTP_PROXY</h2>"HTTP_PROXY"
+	<h2>SERVER_SOFTWARE</h2>"SERVER_SOFTWARE"
 	<h2>$GET</h2>"($GET)"
 	<h2>$POST</h2>"($POST)"
 	<h2>$SERVER</h2>"(string {<table>} (join (map (fn (x) (string {<tr><td>} (x 0) {</td><td>} (x 1) "</td></tr>")) ($SERVER))) "</table>")"
 ;; @param <view> a string containing the view
 ;; <p>Writes a internal link</p>
 ;; 
-(define (link_to link-name view , link-url)
-  	; if Dragonfly runs on newLISP SERVER_SOFTWARE, we cannot
-  	; use .htaccess, so we've to write the "?" into the url
-    ; else we miss it
-	(if (find "newLISP" SERVER_SOFTWARE)
-		(set 'link-url (string "?" view))
-		(set 'link-url (string "/" view))
-	)
-  	(print "<a href=\"" (web-root link-url) "\">" link-name "</a>")
+(define (link_to link-name view)
+  	(print {<a href="} (web-root view) {">} link-name "</a>")
 )
 
 ;; @syntax (Dragonfly:link_to <link_name> <url>)
 ;; @param <int-timeout> an integer containing the number of microseconds after recalling the request-url
 ;; <p>Writes a simple AJAX-updater, e.g. for displaying the time on a website.</p>
 (define (ajax-updater html-elementid request-url str-params timeout)
-	; check for newLISP as SERVER_SOFTWARE, then we prefix a ? before request-url because there's no working .htaccess
-	(when (find "newLISP" SERVER_SOFTWARE)
-		(if (starts-with request-url "/") (pop request-url))
-		(push "/?" request-url)
-	)
 	(set 'request-url (web-root request-url))
 	; 'fetcher' is prevented from entering the global scope because
 	; of the surrounding parenthesis. Meaning, this code won't conflict if

File example-site/dragonfly-framework/plugins-inactive/dragonfly_api.lsp

 				);
 			})("%s/index.html");
 		</script>
-		[/text] (web-root "dragonfly_ajax-api" true) dragonfly-api-directory dragonfly-api-directory)
+		[/text] (web-root "dragonfly_ajax-api") dragonfly-api-directory dragonfly-api-directory)
 	)
 )
 

File example-site/index.cgi

 ;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ;;
 ;;
-;; Start this application on your localhost OS X
+;; To test this locally:
 ;; 
-;; newlisp -http -d PORT -w /Users/USERNAME/Sites/DIRECTORY &
-;; e.g. newlisp -http -d 8080 -w /Users/marc/Sites/dragonfly-web-framework &
+;; $ cd /path/to/example-site
+;; $ ./newlispServer
 ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

File example-site/newlispServer

 #!/bin/bash
 
+NEWLISP_REDIRECTION="./dragonfly-framework/newlisp-redirection.lsp"
+
+if [ ! -f $NEWLISP_REDIRECTION ] ; then
+	echo "ERROR: cannot find file: $NEWLISP_REDIRECTION"
+	exit 1
+fi
+
 echo "If all goes well visit http://localhost:8080 in your browser"
-newlisp -http -d 8080 -w .
+newlisp "$NEWLISP_REDIRECTION" -c -http -d 8080 -w . $*

File example-site/views/dragonfly_errors.html

 			What happens when a user visits the following link?
 		</p>
 		<p>
-			<a href="<%=(setf *link* (web-root "bar" (find "newLISP" SERVER_SOFTWARE)))%>"><%=(string "http://" HTTP_HOST *link*)%></a>
+			<a href="<%=(web-root "bar")%>"><%=(string "http://" HTTP_HOST (web-root "bar"))%></a>
 		</p>
 		<p>
 			Go ahead and click it. I can wait.
 		<p>
 			If it exists, it will be displayed instead of <span class="code">ERROR_TEMPLATE</span>.
 		</p>
-		<p>To see this site's 500 page, click <a href="<%=(web-root "wings/3" (find "newLISP" SERVER_SOFTWARE))%>">here</a>.</p>
+		<p>To see this site's 500 page, click <a href="<%=(web-root "wings/3")%>">here</a>.</p>
 		
 		<h3>Checking the <span class="code" style="font-size:inherit">dragonfly.log</span></h3>
 		

File example-site/views/dragonfly_routes.html

 		<script type="text/javascript" charset="utf-8">
 			var form = $('#wings_form');
 			form.find("input[type='button']").click(function() {
-				var req_url = '<%=(web-root "wings" (find "newLISP" SERVER_SOFTWARE))%>';
+				var req_url = '<%=(web-root "wings")%>';
 				req_url += '/' + $('#wings_id').val();
 				req_url += $('#response_format').val();
 				$('#wings_request').text(req_url);

File example-site/views/dragonfly_welcome.html

 		<h2>newLISP Server</h2>
 		<p>You can easily run this website locally using newLISP's built-in web server:</p>
 		<pre class="code">$ cd path/to/dragonfly-newlisp/example-site
-$ newlisp -http -w . -d 8080</pre>
+$ ./newlispServer</pre>
 		<p>Then just point your browser to:</p>
 		<p><span class="code">http://localhost:8080</span></p>
 		<p>When using newLISP as the server links must have a question mark prepended to them. For example:</p>
-		<p><span class="code">http://localhost:8080/?welcome</p>
+		<p><span class="code">http://localhost:8080/welcome</p>
 		<p class="info"><b>INFORMATION</b><br/>For information on how to configure dragonfly, see <a href="#config">Step 2: Configuring Dragonfly</a> below.</p>
 		
 		<h2>Apache Server</h2>

File example-site/views/partials/continue.html

 
 <script type="text/javascript" charset="utf-8">
 	$('#continue_link').attr('href', function () {
-		var viewpath = "<%=(web-root viewname (find {newLISP} SERVER_SOFTWARE))%>";
+		var viewpath = "<%=(web-root viewname)%>";
 		var ourlink = $("#user_guide_menu dd > a[href='"+viewpath+"']:first");
 		var nextlink = ourlink.parent().nextAll('dd:first').children('a:first').not(ourlink);
 		// if there's a next link in the current column return its href