[99s-extend] Serve static files with cowboy from some applications
Loïc Hoguin
essen at ninenines.eu
Thu Jul 18 12:17:13 CEST 2013
On 07/17/2013 04:47 PM, Alexander Kuleshov wrote:
> Hello,
>
> I have a web application which used cowboy (from master). I need to serve some static files, it's usual web application but i can use usual dispatch something like this:
>
> Dispatch = cowboy_router:compile([
> {'_', [
> {<<"/static/v/[...]">>, cowboy_static, [
> {etag, {attributes, [filepath, filesize, inode, mtime]}},
> {mimetypes, [
> {<<".js">> , [<<"application/javascript">>]},
> {<<".css">>, [<<"text/css">>]},
> {<<".gif">>, [<<"image/gif">>]},
> {<<".png">>, [<<"image/png">>]},
> {<<".jpg">>, [<<"image/jpeg">>]},
> {<<".html">>, [<<"text/html">>]}
> ]},
> {directory, {priv_dir, my_app, [<<"static">>]}}
> ]}
> ]}
> ])
>
> And i try to explain why. In fact, i have one application (this application) which used cowboy and many plugins for it. Every plugin is an erlang application and also every application has own static files. I need routing something like this:
>
> if path /static/v/my_app/index.html than serve index.html from my_app
>
> if path /static/v/other_app/test.js that serve test.js from other_app.
>
> and etc....
>
> Main goal to change: `my_app` from here: {directory, {priv_dir, my_app, [<<"static">>]} dynamically or write custom static handler.
>
> How to do it correctly with cowboy?
Why don't you add one rule per application?
--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu
More information about the Extend
mailing list