Zotonic, Cowboy and custom dispatch

9 views
Skip to first unread message

Olivier Boudeville

unread,
Apr 18, 2020, 8:03:01 AM4/18/20
to Zotonic users
Hi,

Thanks for Zotonic!
I am using a Cowboy-based webserver in charge of several vhosts, one of which being to rely on Zotonic.

Are there Cowboy match rules (as discussed in https://ninenines.eu/docs/en/cowboy/2.7/guide/routing/) that could allow, for some domain/vhost combinations, to branch a given website (and only this one) to Zotonic?
Like in:
       Dispatch = [
                %% Zotonic will handle everything that's not handled in the StaticDispatches
                {'_', StaticDispatches ++ [{'_', ZotonicHandlerModule , ZotonicHandlerOpts}]}
        ],
       cowboy_router:compile(Dispatch).


Thanks in advance for any hint!
Best regards,

Olivier.

Marc Worrell

unread,
Apr 18, 2020, 2:48:51 PM4/18/20
to 'Marc Worrell' via Zotonic users
Hi Olivier,

Good question!

Zotonic is nowadays Cowboy (2) middleware.

In principle it should be possible to use the zotonic middleware dispatcher and request handler directly.
So you don’t need to start the zotonic_http_listener, and instead maybe connect to the middleware?

This is the middleware definition we are using:

cowboy_options() ->
    #{
        middlewares => [ cowmachine_proxy, z_sites_dispatcher, z_cowmachine_middleware ],
        request_timeout => ?HTTP_REQUEST_TIMEOUT,
        env => #{}
    }.

I am really interested in the outcome of your efforts, by using Cowboy it has always been our goal to use Zotonic
in cooperation with other Cowboy systems (Erlang and Elixir).

Cheers!

Marc



--

---
You received this message because you are subscribed to the Google Groups "Zotonic users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotonic-users/816b2172-9f37-4aae-abfe-04e317b91395%40googlegroups.com.

Olivier Boudeville

unread,
Apr 18, 2020, 3:33:12 PM4/18/20
to zotoni...@googlegroups.com
Hi Marc,

Thanks for your answer. I have many developments to perform first, but if I make some progress I will definitively report to this list.

I imagine it may be possible to move such Zotonic logic from a Cowboy middleware to a basic handler that could exist in parallel to others, like I think could be done with Nitrogen, based on what they do with their simple_bridge ([1] was the source of inspiration for the mock-up code I shown).

Cheers!

Olivier.

To view this discussion on the web visit https://groups.google.com/d/msgid/zotonic-users/1906E7BB-8B11-4BBC-A4E4-DFC67E7F7FF2%40me.com.


-- 
Olivier Boudeville

Marc Worrell

unread,
Apr 18, 2020, 4:11:39 PM4/18/20
to zotoni...@googlegroups.com
Hi Olivier,

The middlewares we made are calling local functions, so there must be something possible.

Important is that Zotonic / Cowmachine can take over the request and read the body from the cowboy routines (http/http2) and send data to those routines.

So if zotonic sits after the middleware pipeline, or if you can call the routines yourself then it should definitely be possible.

Looking forward to any further insights!

Cheers, Marc

Sent from my iPad

On 18 Apr 2020, at 21:33, Olivier Boudeville <olivier.b...@online.fr> wrote:


Reply all
Reply to author
Forward
0 new messages