Skip to content

Instantly share code, notes, and snippets.

@WaygoneWilco
Last active March 16, 2018 22:16
Show Gist options
  • Save WaygoneWilco/adc771835528b8af9f67260fe4a8e483 to your computer and use it in GitHub Desktop.
Save WaygoneWilco/adc771835528b8af9f67260fe4a8e483 to your computer and use it in GitHub Desktop.
Luminus app dev notes

Different namespaces:

core - manages the lifecycle of the HTTP server
-main is the entry point
start-app starts the app
stop-app ends the app
luminus defaults to Immutant HTTP server
handler - aggregates all of the routes and then wraps them with necessary middleware
routes - contains the namespaces that are responsible for handling different types of client request
db - reserved for the data model of the application and persistence layer
layout - logic for generating the application layout
middleware - contains custom middleware

For larger applications, we create additional namespaces according to each page (or other understandable organization method).
Then we create separate routes under neach namespace and group them together in the handler namespace using the routes macro in Compojure.
The routes macro creates one final handler (make sure nothing is below the not-found route).

Application Model

Clojure allows us to represent query results by a sequence of maps, which means we don't have to define our app model based on the database.
During dev, we use this:

guestbook/profiles.clj  
{:profiles/dev  {:env {:database-url "jdbc:h2:./guestbook_dev.db"}}  
 :profiles/test {:env {:database-url "jdbc:h2:./guestbook_test.db"}}}

In production we would use and environment variable:
export DATABASE_URL="jdbc:h2:./guestbook.db"

Application Layout

For visual layout and elements on the page
app-context is dynamically bound by guestbook.middleware/wrap-context to either the :servlet-context key in request map or :app-context environment variable.
The resource path is set to resources/templates. Wihtout this, we would have to prefix all templates with templates/.
CSRF is for anti-forgery.

Defining Pages

The pages are defined by creating routes that accept the request parameters and generate the appropriate response.
A route can:

  • Return HTML markup
  • Perform a server-side operation
  • Redirect to a different page
  • Return a specific type of data (a Javascript Object Notation (JSON) string or a file)
    In most cases a page will
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment