hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.63k stars 1.34k forks source link

How to "use" Hapi in production? #1041

Closed simme closed 11 years ago

simme commented 11 years ago

Hey,

Stumbled upon Hapi a while ago and from the looks of it I like it very much. I've started to build something small using it, just to get to know the API.

I do have a few questions however.

First off, I know Hapi is really more focused towards building API's, or at least was. Is it a "dumb idea" to use Hapi to serve front-end web applications too?

Second, when you use Hapi at Walmart etc, how do you structure your code? There must be a reason you build the compose functionality. So do you really write all your "controllers" (to use MVC-lingo) as plugins in separate modules that you version control separately from the server code? Or do you modify the Node paths lookup to find "local" modules?

Say a website has three distinct features, would those be three plugins? How do they share templates in a clean way?

The examples are a bit lacking in this regard, because I guess that for most people just writing a bunch of request handlers in a file together with the routes doesn't really make sense in larger scales. Or maybe I'm just damaged by all this MVC hysteria! ;)

Anyway, I'd really like to start using Hapi because I do like your philosophy and and the API looks super clean. I'm one of those guys who like to obsess over structure though, which often is a bad thing :P

Cheers!

jamalsoueidan commented 11 years ago

You should just develop your API, and use AngularJS as front-end application.

You can still use NodeJs(HapiJS) to serv your files through public folder, but I would rather use nginx for that.

There is no one way of structuring your application, use whatever ways you like. :)

simme commented 11 years ago

Actually I was thinking of using Ember! ;) But having fallbacks for non-javascript would be nice.

I get that there's no "one way". Just asking to see what patterns other people are using!

jamalsoueidan commented 11 years ago

search google "javascript modularization"

Box Tech Talk: Scalable JavaScript Application Architecture http://www.youtube.com/watch?v=mKouqShWI4o

simme commented 11 years ago

Thanks! I already know that stuff though. I'm wondering of patterns that are developed to fit well in the Hapi API and plugin/helper structure though.

But I guess I'll just have to find my own way then :)

jamalsoueidan commented 11 years ago

Hmm,,

If the creator can join us, he might have the best to answer :)

hueniverse commented 11 years ago

@simme yes, you should use hapi for your web server. API is the default behavior but hapi has full support for building web apps. We use plugins extensively and break every part of the server into a plugin. This allows us to split the work across a large team, roll back only the problematic plugin, deploy different combinations on different machines, etc.

We have an open issue to add plugin examples.

jamalsoueidan commented 11 years ago

This is what you are searching for :)

https://github.com/hueniverse/postmile

simme commented 11 years ago

Oh, thanks @jamalsoueidan :)

And thanks @hueniverse for the answer!

jamalsoueidan commented 11 years ago

You welcome :+1:

It's @hueniverse work:D