appengine-magic handling static resources

30 views
Skip to first unread message

László Török

unread,
Apr 5, 2011, 5:13:26 PM4/5/11
to clojure...@googlegroups.com
Hi,

probably a dummy question, but does appengine-magic handle static resources the same way as the GAE production environment?

"Just put all static files into your application's war/ directory. If you put a file called index.html there, it will become a default welcome file."
(from ae-magic readme)

"By default, App Engine makes all files in the WAR available as static files except JSPs and files in WEB-INF/. Any request for a URL whose path matches a static file serves the file directly to the browser—even if the path also matches a servlet or filter mapping. You can configure which files App Engine treats as static files using the appengine-web.xml file."

I put an index.html into /resources and /war too. If I reference it directly with /index.html I get HTTP 500 handler returned nil (no response map).

If I serve it up with ae/open-resource-stream "index.html" in a ring handler it works.

What am I doing wrong? How should I do it so it works in dev and prod environment?

Thanks,

Las

Constantine Vetoshev

unread,
Apr 5, 2011, 8:58:22 PM4/5/11
to clojure...@googlegroups.com, László Török
On Tue, Apr 5, 2011 at 2:13 PM, László Török <ltor...@gmail.com> wrote:
> "Just put all static files into your application's war/ directory. If you
> put a file called index.html there, it will become a default welcome file."
> (from ae-magic readme)

Right. As long as you're serving content from ae/serve, it will work.
It will also work when deployed, provided you didn't forget to run
"lein appengine-prepare".

> I put an index.html into /resources and /war too. If I reference it directly
> with /index.html I get HTTP 500 handler returned nil (no response map).

I'm not sure why this happens to you. See below for a sample core.clj
file with which everything works for me.

> If I serve it up with ae/open-resource-stream "index.html" in a ring handler
> it works.

Right. This served up the one from resources/. This is meant for use
with server-side templates (e.g., Enlive). It's inconvenient, and
probably inefficient, to do this for standard static files.

> What am I doing wrong? How should I do it so it works in dev and prod
> environment?

I'm not sure why this doesn't work for you. With appengine-magic, you
must use ae/serve, or preprocess your app using "lein
appengine-prepare".

Starting from a completely new Leiningen project, here's a sample
src/mytest/core.clj:

(ns mytest.core
(:require [appengine-magic.core :as ae]))

(defn mytest-app-handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, world!"})

(ae/def-appengine-app mytest-app #'mytest-app-handler)

Here's a sample war/index.html:

<html>
<head>
<title>test title</title>
</head>
<body>
<p>this is a test
</body>
</html>

For completeness, here is my project.clj:

(defproject mytest "1.0.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.2.1"]]
:dev-dependencies [[appengine-magic "0.4.1"]
[swank-clojure "1.3.0"]])

Here's how you use it from the REPL:

user=> (load "mytest/core")
nil
user=> (in-ns 'mytest.core)
#<Namespace mytest.core>
mytest.core=> (ae/serve mytest-app)

Now, when I access http://localhost:8080, I get the index.html file.

Reply all
Reply to author
Forward
0 new messages