0

I have limited experience with D8 and custom routes.

Current mobile video system for client takes a scheme-less url for the video like so

https://example.com/mobile-video/some-video-desktop.azureedge.net

The routing has worked fine until we had a vendor change for video hosting and the new URLs include slashes and query strings which may or may not be the issue.

mobilevideo.routing.yml looks like

mobilevideo.content:
  path: '/mobile-video/{vguid}'
  defaults:
    _controller: 'Drupal\mobilevideo\Controller\MobileVideoController::content'
    _title: 'Mobile Video'
  requirements:
    _permission: 'access content'
    vguid: '^[-a-zA-Z0-9.\/?=]+'

Prior to today the validation was just '^[-a-zA-Z0-9.]+'

So testing the new URLs I am getting 404s. But if the parameter passed to the mobilevideo.routing.yml fails validation a 404 is the correct response so I assume the issue is validation. https://www.drupal.org/docs/8/api/routing-system/parameters-values-validation-in-routes

So I changed the validation from vguid: '^[-a-zA-Z0-9.]+' to vguid: '^[-a-zA-Z0-9.\/?=]+' that had no effect and I also tried '.+' and also the original without ? and = with no change.

I should note that the original URLs with no slashes worked continously through all of this and that each change was followed by clearing all caches.

Also tried removing validation entirely and that also failed so I am wondering if my path cannot include slashes in the parameter for reasons beyond validation?

What should my next step be in debugging this?

A full example URL will look like

https://example.com/mobile-video/someidhere.cloudfront.net/sessions/forty-characters-or-more-of-vguid-here.mp4?invocationId=thirty-more-chars-here

UPDATE Based on info re optional parameters and the comments on this post I added four more parameters and default values of '' for each updating mobilevideo.routing.yml to

mobilevideo.content:
  path: '/mobile-video/{vguid}/{vguidtwo}/{vguidhtree}/{vguidfour}/{vguidfive}'
  defaults:
    _controller: 'Drupal\mobilevideo\Controller\MobileVideoController::content'
    _title: 'Mobile Video'
    vguid: ''
    vguidtwo: ''
    vguidthree: ''
    vguidfour: ''
    vguidfive: ''
  requirements:
    _permission: 'access content'
    vguid: '^[-a-zA-Z0-9.]+'
    vguidtwo: '^[-a-zA-Z0-9.]+'
    vguidthree: '^[-a-zA-Z0-9.]+'
    vguidfour: '^[-a-zA-Z0-9.]+'
    vguidfive: '^[-a-zA-Z0-9.]+'

Then updated the controller to use public function content($vguid, $vguidtwo, $vguidthree, $vguidfour, $vguidfive) { and assemble the URL based on that array.

Attempting to flush the cache gets The website encountered an unexpected error. Please try again later.. What did I miss?

4

1 Answer 1

0

My solution was to modify the javascript directing traffic to the mobile video page so that it replaced the slashes with triple underscores.

urlNoProtocol = src.replace(/\//i, "___");

The validation in mobilevideo.routing.yml was updated to vguid: '^[-a-zA-Z0-9._?=]+'

Then in MobileVideoController.php the content() function was updated to reverse the replacement.

$url = preg_replace('/___/','/', $vguid);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.