amazeelabs / silverback_cdn_redirect
Provide redirect information to CDNs.
Installs: 36 681
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 1
Open Issues: 1
Type:drupal-module
pkg:composer/amazeelabs/silverback_cdn_redirect
Requires
- cweagans/composer-patches: ^1.7.3
README
To be used with static websites, hosted on a CDN (e.g. Gatsby and Netlify). Solves two problems:
- Can resolve redirects that are not stored in CDN config, which is necessary, since Drupal's redirect module creates a redirect for each path change, which can be a lot. In that case, the redirect is resolved by rewriting the request to Drupal.
- Rewrite paths not know by the CDN, to client-side rendered pages. Useful for pages that should not be rendered statically.
Flowchart!
flowchart
subgraph Drupal
RedirectCheck{Drupal redirect exists?}
EntityCheck{Drupal page exists?}
RequestNotFound[Fetch 404 from CDN]
RequestCSR[Fetch CSR template from CDN]
end
subgraph CDN
Request(User navigates to path)
CDNCheck{Static page exists?}
CDNDeliver{{Respond with static page}}
CDNRedirect{{Respond with redirect from Drupal}}
CDNRewrite{{Respond with content from Drupal}}
end
CDNCheck -- no --> RedirectCheck
RedirectCheck -- yes --> CDNRedirect
RedirectCheck -- no --> EntityCheck
Request --> CDNCheck
CDNCheck -- yes --> CDNDeliver
EntityCheck -- no --> RequestNotFound
EntityCheck -- yes --> RequestCSR
RequestNotFound ----> CDNRewrite
RequestCSR ----> CDNRewrite
Loading
Drupal config
- Patch Drupal with a patch from #2741939
- Enable the module
- Set the settings, for example:
drush cset silverback_cdn_redirect.settings base_url https://my-gatsby.site drush cset silverback_cdn_redirect.settings 404_path /404 drush cset silverback_cdn_redirect.settings should_prefix_404_path true
Gatsby config
- Add gatsby-plugin-netlify package
- Configure the catch-all redirect in
createPagescreateRedirect({ fromPath: '/*', toPath: `https://my-drupal.site/cdn-redirect/:splat`, statusCode: 200, });
Note:statusCode: 200is required to "hide" the request to backend from the browser.