[99s-extend] Serve static files with cowboy from some applications

Alexander Kuleshov akuleshov at tpip.net
Wed Jul 17 16:47:43 CEST 2013


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?

Thank you.

-- 
Alex Kuleshov
Software Developer

email: ak at travelping.com
phone: +77172227194
mobile: +77019442517

----------------- enabling your networks ---------------------
Travelping GmbH               phone: +49-391-8190990
Roentgenstr. 13               fax: +49-391-819099299
D-39108 Magdeburg             email: info at travelping.com
GERMANY                       web: http://www.travelping.com

Company Registration: Amtsgericht Stendal Reg No.: HRB 10578
Geschaeftsfuehrer: Holger Winkelmann | VAT ID No.: DE236673780
--------------------------------------------------------------



More information about the Extend mailing list