mattbrailsford / umbraco-headrest

A REST based headless approach for Umbraco
MIT License
83 stars 19 forks source link

Routing conflicts in mixed installation #4

Closed jamescoxhead closed 5 years ago

jamescoxhead commented 5 years ago

Hi Matt,

h5yr for putting Headrest together - we started looking at self-hosting a headless version of Umbraco a few weeks back and Headrest came along at a perfect time.

We've been trying out Headrest in a mixed installation and have had a few routing issues when trying to access the website front end. I've configured the endpoint to be available at /api/ which works fine. In the back office, the links to the pages is replaced with an error ("This document is published but its url would collide with content). If I go to mysite.local/ I get taken to the JSON output, however if I enter the page's full URL I can get to the front end.

I've tinkered with the HeadRestUrlProvider and found that inheriting from the DefaultUrlProvider and moving the contents of the GetUrl method to the GetOtherUrls method which seems to have done the trick. I'm happy to create a PR with my changes if you think this is an issue which should be fixed.

mattbrailsford commented 5 years ago

Hmm, sounds like I might need a way to signal a page would be accessible as both an api and a standard route, and set either the main or other urls properties accordingly.

I've only really tested a site being one or the other, so will have to run some specific tests for this one.

mattbrailsford commented 5 years ago

I'm thinking maybe adding an Enum option to HeadRestOptions for something like RouteMode with 2 options of HeadRestRouteMode.Dedicated and HeadRestRouteMode.Mixed with dedicated being the default then you can choose accordingly.

I was wondering if it could be worked out automatically which I think it kinda can, but thinking explicit might be best. Only way I could see it working automatically is if it searches for content with a URL matching basePath and if it matches, it assumes it's an override and makes the API url the primary URL, but if no content matches the basePath then it assumes you are wanting a mixed mode and so makes the API url an "Other Url". I get the feeling that someone might come back though saying that's not the case so I think the Enum flag might be better.

mattbrailsford commented 5 years ago

@jamescoxhead created PR #5 as a fix for this. Please give that a try and see how you get on. I'll close this issue and we'll continue the discussion on the PR.