0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Convert the markdown_middleware example to a release

This commit is contained in:
Loïc Hoguin 2013-10-22 09:10:24 +02:00
parent 4769412daa
commit 36ba174224
9 changed files with 1614 additions and 46 deletions

View file

@ -0,0 +1,6 @@
PROJECT = markdown_middleware
DEPS = cowboy
dep_cowboy = pkg://cowboy master
include ../../erlang.mk

View file

@ -1,24 +1,25 @@
Cowboy Middleware Middleware example
================= ==================
To compile this example you need rebar in your PATH. To try this example, you need GNU `make`, `git` and
[relx](https://github.com/erlware/relx) in your PATH.
Type the following command: To build the example, run the following command:
```
$ rebar get-deps compile ``` bash
$ make
``` ```
You can then start the Erlang node with the following command: To start the release in the foreground:
```
./start.sh ``` bash
$ ./_rel/bin/hello_world_example console
``` ```
Cowboy will serve all the files you put in the priv/ directory. If you request Then point your browser at
a .html file that has corresponding .md file that has been modified more [http://localhost:8080/video.html](http://localhost:8080/video.html).
recently than the .html file, the markdown file will be converted to HTML and
served by Cowboy.
HTML5 Video Example Cowboy will serve all the files you put in the `priv` directory.
------------------- If you request a `.html` file that has a corresponding `.md` file
that has been modified more recently than the `.html` file, the
Open http://localhost:8080/video.html in your favorite browser. Markdown file will be converted to HTML and served by Cowboy.

View file

@ -1,8 +0,0 @@
{deps, [
{cowboy, ".*",
{git, "git://github.com/extend/cowboy.git", "master"}},
{mimetypes, ".*",
{git, "git://github.com/spawngrid/mimetypes.git", "master"}},
{erlmarkdown, ".*",
{git, "git://github.com/ericbmerritt/erlmarkdown.git", "rv"}}
]}.

View file

@ -0,0 +1,2 @@
{release, {markdown_middleware_example, "1"}, [markdown_middleware]}.
{extended_start_script, true}.

File diff suppressed because it is too large Load diff

View file

@ -22,8 +22,8 @@ maybe_generate_markdown(Path) ->
end. end.
resource_path(Path) -> resource_path(Path) ->
{ok, Cwd} = file:get_cwd(), PrivDir = code:priv_dir(markdown_middleware),
filename:join([Cwd, "priv", Path]). filename:join([PrivDir, Path]).
source_path(Path) -> source_path(Path) ->
<< (filename:rootname(Path))/binary, ".md" >>. << (filename:rootname(Path))/binary, ".md" >>.

View file

@ -1,15 +0,0 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(markdown_middleware).
%% API.
-export([start/0]).
%% API.
start() ->
ok = application:start(crypto),
ok = application:start(cowlib),
ok = application:start(ranch),
ok = application:start(cowboy),
ok = application:start(markdown_middleware).

View file

@ -15,7 +15,11 @@ start(_Type, _Args) ->
{'_', [ {'_', [
{"/[...]", cowboy_static, [ {"/[...]", cowboy_static, [
{directory, {priv_dir, markdown_middleware, []}}, {directory, {priv_dir, markdown_middleware, []}},
{mimetypes, {fun mimetypes:path_to_mimes/2, default}} {mimetypes, [
{<<".html">>, [<<"text/html">>]},
{<<".mp4">>, [<<"video/mp4">>]},
{<<".ogv">>, [<<"video/ogg">>]}
]}
]} ]}
]} ]}
]), ]),

View file

@ -1,3 +0,0 @@
#!/bin/sh
erl -pa ebin deps/*/ebin -s markdown_middleware \
-eval "io:format(\"Point your browser at http://localhost:8080/video.html~n\")."