From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Hendy Subject: Re: [ANN, OT] Emacs web-server, a new option for serving Org-mode files Date: Sun, 12 Jan 2014 08:40:03 -0600 Message-ID: References: <87zjn24cgx.fsf@gmail.com> <87mwj2ywy2.fsf@gmail.com> <874n5ayriq.fsf@gmail.com> <878uumt17y.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2MCs-0002R0-5z for emacs-orgmode@gnu.org; Sun, 12 Jan 2014 09:40:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W2MCq-0006Cq-J0 for emacs-orgmode@gnu.org; Sun, 12 Jan 2014 09:40:06 -0500 Received: from mail-oa0-x233.google.com ([2607:f8b0:4003:c02::233]:49306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W2MCq-0006B0-Bn for emacs-orgmode@gnu.org; Sun, 12 Jan 2014 09:40:04 -0500 Received: by mail-oa0-f51.google.com with SMTP id m1so6968617oag.38 for ; Sun, 12 Jan 2014 06:40:03 -0800 (PST) In-Reply-To: <878uumt17y.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: Org Mode Mailing List On Sat, Jan 11, 2014 at 7:53 PM, Eric Schulte wrote: > John Hendy writes: > >> On Sat, Jan 11, 2014 at 6:26 PM, Eric Schulte wrote: >>> John Hendy writes: >>> >>>> On Sat, Jan 11, 2014 at 4:29 PM, Eric Schulte wrote: >>>>>> >>>>>> The "Hello world" example worked splendidly for me out of the box. I'm >>>>>> having a bit of difficulty with serving up a file via this example: >>>>>> http://eschulte.github.io/emacs-web-server/File-Server.html#File-Server >>>>>> >>>>>> Perhaps I don't understand how the function is supposed to work... It >>>>>> says that the docroot is the current working directory in the example, >>>>>> so I cd'd to a directory with an .html file in it, started `emacs -Q` >>>>>> from the command line, ran `M-x load-file RET ~/.emacs`, and then >>>>>> evaluated the code from the example in the *scratch* buffer. I'm >>>>>> getting the 404 error. Should I be modifying that code somehow? >>>>>> >>>>> >>>>> Since the value of the default-directory variable may not be easy to >>>>> predict, you're probably better off changing >>>>> >>>>> (docroot default-directory) >>>>> >>>>> to >>>>> >>>>> (docroot "/full/path/to/directory/of/org/files") >>>>> >>>>> I only used default-directory in the example because I couldn't think of >>>>> a good static path which would probably exist on most people's systems. >>>> >>>> Hmmm. Still having trouble. I tried: >>>> >>>> (lexical-let ((docroot "/home/jwhendy/Desktop/e-web-server-test")) >>>> (ws-start >>>> (list (cons (cons :GET ".*") >>>> (lambda (request) >>>> (with-slots (process headers) request >>>> (let ((path (substring (cdr (assoc :GET headers)) 1))) >>>> (if (ws-in-directory-p docroot path) >>>> (ws-send-file process (expand-file-name path docroot)) >>>> (ws-send-404 process))))))) >>>> 9003)) >>>> >>>> That directory contains just two .org files. When I open >>>> localhost:9003, it downloads a file called `download`, containing the >>>> following: >>>> >>>> HTTP/1.1 500 Internal Server Error >>>> Content-type: text/plain >>>> >>>> Caught Error: (error "IO error reading >>>> /home/jwhendy/Desktop/e-web-server-test: Is a directory") >>>> >>>> So, I then tried with the first line like so (trailing slash): >>>> >>>> (lexical-let ((docroot "/home/jwhendy/Desktop/e-web-server-test/")) >>>> >>>> Then I'm back to the 404 error. Sorry if I'm being dense and didn't >>>> follow something else implied. I noticed the tutorial mentioned >>>> mime-types. Do I need to set something with xdg-mime for .org files or >>>> do anything else other than simply doing (require 'web-server)? >>>> >>>> Since the hello world example worked, I'm assuming the setup is at >>>> least partially sound. >>>> >>> >>> Oh, the example is confusing, I just updated both the example and the >>> documentation. The problem is that the example serves files, but not >>> directory listings. So since you just requested "/" it said there was >>> nothing there. If you pull down the latest version of the web-server >>> that example will now give a directory listing when "/" is requested. >> >> So instead of a path, should I have provided a specific file name? I >> guess I was just going by the description: "The following example >> implements a file server which will serve files from..." Perhaps I'm >> still not understanding what, exactly, the web-server does! >> >> Do you point it to *a* file, or a directory containing numerous files? >> >> Or just to understand better, can you give a concrete example of what >> I could do with my example path which contains .org files (perhaps via >> the original code before you modified it, just so I understand the >> intent). >> >> Or should I have been doing something like http://localhost:9003/file.org? >> > > Yes, the above would have worked with the original. It assumed you > would give it a file name as the end of the URL. I tried two things: ;;; file-server.el --- serve any files using Emacs Web Server (lexical-let ((docroot "/home/jwhendy/Desktop/e-web-server-test/")) (ws-start (lambda (request) (with-slots (process headers) request (let ((path (substring (cdr (assoc :GET headers)) 1))) (if (ws-in-directory-p docroot path) (if (file-directory-p path) (ws-send-directory-list process (expand-file-name path docroot) "^[^\.]") (ws-send-file process (expand-file-name path docroot))) (ws-send-404 process))))) 9003)) - If I go to localhost:9003, I get 404 not found. - If I go to localhost:9003/personal.org (I threw my non-work notes file into that directory), it downloads the file. Next, I replaced the first line with a full path to personal.org: (lexical-let ((docroot "/home/jwhendy/Desktop/e-web-server-test/personal.org")) Now I get the following error (in the browser) for localhost:9003: Caught Error: (void-function ws-send-directory-list) If I do localhost:9003/personal.org, it also downloads the file. I feel I must be drastically overcomplicating this somehow... Thanks again for persisting with me! John [snipped emacs terminology discussion] >> Sorry for the denseness above. I'm not a super web guy, so I'm >> probably just getting hung up on poor understanding of the term "web >> server" and what exactly it would do in this context. For my limited >> Apache experience I suppose I always had an index.html with links >> elsewhere, so that's sort of the extent of my knowledge. >> > > No problem, happy to help and I appreciate your feedback on what parts > are not obvious. > > Best, > >> >> >> Thanks for all the assistance! >> John >> >>> >>> Thanks, >>> >>>> >>>> >>>> Thanks, >>>> John >>>> >>>>> >>>>>> >>>>>> >>>>>> Thanks and great work -- this is really neat! >>>>> >>>>> Thanks, and please do let me know if anything else doesn't work as >>>>> expected. >>>>> >>>>> Best, >>>>> >>>>>> >>>>>> John >>>>>> >>>>>> >>>>>>> Best, >>>>>>> >>>>>>> Footnotes: >>>>>>> [1] https://github.com/eschulte/emacs-web-server >>>>>>> >>>>>>> [2] http://eschulte.github.io/emacs-web-server/tutorials/#sec-1 >>>>>>> >>>>>>> [3] http://eschulte.github.io/emacs-web-server/Org_002dmode-Export.html#Org_002dmode-Export >>>>>>> >>>>>>> [4] https://github.com/eschulte/emacs-web-server/blob/master/examples/013-org-export-service.el >>>>>>> >>>>>>> [5] https://github.com/eschulte/emacs-web-server/blob/master/examples/011-org-agenda.el >>>>>>> >>>>>>> [6] https://github.com/eschulte/org-ehtml >>>>>>> >>>>>>> [7] http://eschulte.github.io/emacs-web-server/benchmark/ >>>>>>> >>>>>>> -- >>>>>>> Eric Schulte >>>>>>> https://cs.unm.edu/~eschulte >>>>>>> PGP: 0x614CA05D >>>>>>> >>>>> >>>>> -- >>>>> Eric Schulte >>>>> https://cs.unm.edu/~eschulte >>>>> PGP: 0x614CA05D >>> >>> -- >>> Eric Schulte >>> https://cs.unm.edu/~eschulte >>> PGP: 0x614CA05D > > -- > Eric Schulte > https://cs.unm.edu/~eschulte > PGP: 0x614CA05D