Server select views engine throws error
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.
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.
@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 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.
@hueniverse thanks for the reply, I solved it through configuration which worked better and seemed cleaner.
@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.
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
@luismatute you need to use two plugins, one for each connection.