[erlang-questions] Code organization for virtual websites based on Cowboy

lloyd@REDACTED lloyd@REDACTED
Sun Apr 27 21:23:39 CEST 2014


Hi,

Sounds promising. I'll have to experiment. 

This would be a great tutorial. It'll be a awhile before I can clear the deck to give it a try. But if I can achieve success, I'll consider writing up the tutorial.

Many thanks. And thanks again for your great work with Cowboy and other Open Source apps.

Best wishes,

Lloyd


-----Original Message-----
From: "Loïc Hoguin" <essen@REDACTED>
Sent: Sunday, April 27, 2014 1:59pm
To: lloyd@REDACTED, "erlang-questions@REDACTED" <erlang-questions@REDACTED>
Subject: Re: [erlang-questions] Code organization for virtual websites based on Cowboy

Hi,

Sorry for the late reply, I had to think a little about it.

I would have a single application for all handlers.

I would create two folders under src, one per host. For example:

  src/www
  src/chat

Static files I would probably want to have a specific host for them so I 
wouldn't need to separate (I could create extra folders for the 
host-specific stuff, but there's no reason to separate jquery and others).

On initialization I would have the file src/my_app.erl call a predefined 
function for each host to get their routing rules, for example 
www_routes:get() ++ chat_routes:get().

I would make sure that I only have handlers or helpers in this 
application. I would make separate applications for different parts of 
the system, for example an application for managing sessions, an 
application for chat communication, an application for www business 
logic, etc. and I would call these applications from the handlers.

Does this answer your question?

On 04/25/2014 12:52 AM, lloyd@REDACTED wrote:
> Hello,
>
> Suppose we have n virtual websites served out of a single Cowboy server.
>
> I get, I think, this:
>
> Routes = [Host1, Host2, ... HostN].
> Host1 = {HostMatch, PathsList}.
> Host2 = {HostMatch, Constraints, PathsList}.
>
> But two questions trouble me:
>
> 1) What is the best directory structure to organize handlers and site-specific code to keep site code and resources separated and and easy to maintain?
>
> 2) Can these sites be developed and tested through localhost, or is a more elaborate set-up involving, say more than one box on a local network with local DNS server?
>
> Many thanks,
>
> LRP
>
>
> *********************************************
> My books:
>
> THE GOSPEL OF ASHES
> http://thegospelofashes.com
>
> Strength is not enough. Do they have the courage
> and the cunning? Can they survive long enough to
> save the lives of millions?
>
> FREEIN' PANCHO
> http://freeinpancho.com
>
> A community of misfits help a troubled boy find his way
>
> AYA TAKEO
> http://ayatakeo.com
>
> Star-crossed love, war and power in an alternative
> universe
>
> Available through Amazon or by request from your
> favorite bookstore
>
>
> **********************************************
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu





More information about the erlang-questions mailing list