Skip to content

Commit

Permalink
Merge pull request #35 from inaka/harenson.26.static-files-as-an-env-…
Browse files Browse the repository at this point in the history
…variable-is-not-good-for-releases

[Fix #26] Fix static_files trail
  • Loading branch information
Brujo Benavides committed Nov 27, 2015
2 parents e9b1062 + 74fb435 commit 1f81947
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TEST_DEPS = xref_runner mixer shotgun

dep_sync = git https://github.com/inaka/sync.git 0.1.3
dep_jiffy = git https://github.com/davisp/jiffy.git 0.14.3
dep_trails = git https://github.com/inaka/cowboy-trails.git 0.0.2
dep_trails = git https://github.com/inaka/cowboy-trails.git 0.1.0
dep_xref_runner = git https://github.com/inaka/xref_runner.git 0.2.2
dep_mixer = git https://github.com/inaka/mixer.git 0.1.4
dep_shotgun = git https://github.com/inaka/shotgun.git 0.1.12
Expand Down
20 changes: 18 additions & 2 deletions src/cowboy_swagger_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ handle_get(Req, State) ->
%% trails routes for both: static content (Swagger-UI) and this handler
%% that returns the `swagger.json'.
trails() ->
StaticFiles = application:get_env(
cowboy_swagger, static_files, "priv/swagger"),
StaticFiles =
case application:get_env(cowboy_swagger, static_files) of
{ok, Val} -> Val;
_ -> filename:join(cowboy_swagger_priv(), "swagger")
end,
Static1 = trails:trail(
"/api-docs",
cowboy_static,
Expand All @@ -80,3 +83,16 @@ trails() ->
Handler = trails:trail(
"/api-docs/swagger.json", cowboy_swagger_handler, [], MD),
[Static1, Handler, Static2].

%% @private
-spec cowboy_swagger_priv() -> string().
cowboy_swagger_priv() ->
case code:priv_dir(cowboy_swagger) of
{error, bad_name} ->
filename:join(
[ filename:dirname(code:which(cowboy_swagger_handler))
, ".."
, "priv"
]);
Path -> Path
end.

0 comments on commit 1f81947

Please sign in to comment.