Serve static files
This commit is contained in:
parent
fd79f31dd2
commit
06bd134426
2 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
%% -*- mode: erlang -*-
|
||||
|
||||
{["static", '*'], 'elmdap-static', []}.
|
||||
{["uid", uid], 'elmdap-uid', []}.
|
||||
|
|
30
src/elmdap-static.lfe
Normal file
30
src/elmdap-static.lfe
Normal file
|
@ -0,0 +1,30 @@
|
|||
(defmodule elmdap-static
|
||||
(export (init 1)
|
||||
(content_types_provided 2)
|
||||
(resource_exists 2)
|
||||
(to_bytes 2)))
|
||||
|
||||
(include-lib "webmachine/include/webmachine.hrl")
|
||||
|
||||
(defun init (args)
|
||||
#(ok undefined))
|
||||
|
||||
(defun content_types_provided (req-data state)
|
||||
`#([#("application/javascript" to_bytes)
|
||||
#("text/html" to_bytes)]
|
||||
,req-data ,state))
|
||||
|
||||
(defun resource_exists (req-data state)
|
||||
(let* ((path (map-path (wrq:disp_path req-data)))
|
||||
(exists? (filelib:is_file path)))
|
||||
`#(,exists? ,req-data ,state)))
|
||||
|
||||
(defun to_bytes (req-data state)
|
||||
(let ((`#(ok ,bytes) (file:read_file
|
||||
(map-path (wrq:disp_path req-data)))))
|
||||
(tuple bytes req-data state)))
|
||||
|
||||
(defun map-path (path)
|
||||
(let* ((`#(ok ,app) (application:get_application 'elmdap-static))
|
||||
(priv (code:priv_dir app)))
|
||||
(filename:join priv path)))
|
Loading…
Reference in a new issue