| 1 |
%% Feel free to use, reuse and abuse the code in this file. |
| 2 |
|
| 3 |
%% @private |
| 4 |
-module(file_server_app). |
| 5 |
-behaviour(application). |
| 6 |
|
| 7 |
%% API. |
| 8 |
-export([start/2]). |
| 9 |
-export([stop/1]). |
| 10 |
|
| 11 |
%% API. |
| 12 |
|
| 13 |
start(_Type, _Args) -> |
| 14 |
Dispatch = cowboy_router:compile([ |
| 15 |
{'_', [ |
| 16 |
{"/[...]", cowboy_static, {priv_dir, file_server, "", [ |
| 17 |
{mimetypes, cow_mimetypes, all}, |
| 18 |
{dir_handler, directory_h}, |
| 19 |
{charset, <<"utf-8">>} |
| 20 |
]}} |
| 21 |
]} |
| 22 |
]), |
| 23 |
{ok, _} = cowboy:start_clear(http, [{port, 8080}], #{ |
| 24 |
env => #{dispatch => Dispatch}, |
| 25 |
middlewares => [cowboy_router, directory_lister, cowboy_handler] |
| 26 |
}), |
| 27 |
file_server_sup:start_link(). |
| 28 |
|
| 29 |
stop(_State) -> |
| 30 |
ok = cowboy:stop_listener(http). |