Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amazeelabs/silverback_cdn_redirect
https://github.com/amazeelabs/silverback_cdn_redirect
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/amazeelabs/silverback_cdn_redirect
- Owner: AmazeeLabs
- Created: 2021-06-28T14:44:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-26T08:16:38.000Z (4 months ago)
- Last Synced: 2024-10-12T09:23:01.730Z (4 months ago)
- Language: PHP
- Size: 55.7 KB
- Stars: 0
- Watchers: 8
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Silverback CDN Redirect
To be used with static websites, hosted on a CDN (e.g. Gatsby and Netlify).
Solves two problems:1. 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.
2. Rewrite paths not know by the CDN, to client-side rendered pages. Useful for
pages that should not be rendered statically.## Flowchart!
```mermaid
flowchart
subgraph Drupal
RedirectCheck{Drupal redirect exists?}
EntityCheck{Drupal page exists?}
RequestNotFound[Fetch 404 from CDN]
RequestCSR[Fetch CSR template from CDN]
endsubgraph 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}}
endCDNCheck -- no --> RedirectCheck
RedirectCheck -- yes --> CDNRedirect
RedirectCheck -- no --> EntityCheck
Request --> CDNCheck
CDNCheck -- yes --> CDNDeliver
EntityCheck -- no --> RequestNotFound
EntityCheck -- yes --> RequestCSR
RequestNotFound ----> CDNRewrite
RequestCSR ----> CDNRewrite
```## Drupal config
- Patch Drupal with a patch from
[#2741939](https://www.drupal.org/project/drupal/issues/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](https://www.gatsbyjs.com/plugins/gatsby-plugin-netlify)
package
- Configure the catch-all redirect in `createPages`
```js
createRedirect({
fromPath: '/*',
toPath: `https://my-drupal.site/cdn-redirect/:splat`,
statusCode: 200,
});
```
Note: `statusCode: 200` is required to "hide" the request to backend from the
browser.