hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Server select views engine throws error

Open StevenWeathers opened this issue 11 years ago • 7 comments

Trying to set view paths per connection results in "Error: Cannot set views manager more than once"

Using method below server.select("x").views({});

The goal is to separate views by target device sets such as mobile and desktop while sharing same codebase and routes effectively.

StevenWeathers avatar Dec 17 '14 01:12 StevenWeathers

Having a similar experience with server.select('http').expose seems that it can only be set once and the last one set takes precedence. server.select('http').expose({protocol: 'http'}) server.select('secure').expose({protocol: 'https'})

then calling request.server.plugins['plugin-name'].protocol the result is always the last one defined.

mickr avatar Dec 24 '14 04:12 mickr

@StevenWeathers I can't help without knowing what the connections options are (e.g. if there is any overlap in labels that will cause this error).

@bc-mick expose() has two flavors. Use the one that sets just the property, not the full object. The framework can't possibly know what to do with multiple full objects you set other than override.

hueniverse avatar Jan 04 '15 03:01 hueniverse

@hueniverse I will get you an example Monday but I can say for certain the label and ports do not conflict for the connections, which is the two key differentiators I was using. It seems like the views manager doesn't differentiate from the select method.

StevenWeathers avatar Jan 04 '15 03:01 StevenWeathers

@hueniverse thanks for the reply, I solved it through configuration which worked better and seemed cleaner.

mickr avatar Jan 04 '15 03:01 mickr

@StevenWeathers right. My mistake. Adding a views manager is actually based on the current realm, not on the selection. If you notice in the docs, it sets the server's manager, not the connection. To isolate view managers per connection you need to use plugins and load them separately per connection. If you think this functionality is useful for others, feel free to open an issue under hapijs/vision.

hueniverse avatar Jan 04 '15 03:01 hueniverse

Forgive me if this is a no brainer but how would you handle multiple connections' views? lets say there is an admin and a public connection and I have the views separated on different directories, how would this be? I thought setting the views manager per connection was the way

pipa avatar Apr 06 '15 16:04 pipa

@luismatute you need to use two plugins, one for each connection.

hueniverse avatar Apr 14 '15 20:04 hueniverse