diff --git a/Makefile b/Makefile index 5b11e9a..92efd8e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/cowboy_swagger_handler.erl b/src/cowboy_swagger_handler.erl index d873c64..a9a824b 100644 --- a/src/cowboy_swagger_handler.erl +++ b/src/cowboy_swagger_handler.erl @@ -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, @@ -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.