'Using 11ty as CMS for backend system
Not 100% sure if this is possible but the goal is to have a single point of entry (naked domain https://example.com) for entire system
- Backend/application (load balanced) is using either LEMP/Rails/Node, etc and occupies main domain ("www" redirects to this) and proxied via nginx
- Do not want to build a CMS inside and have experience using 11ty + Netlify (which is great)
- Headless CMS (example Prismic.io) involves a lot more setup than anticipated
- Marketing (public) pages are fairly limited (5-10 pages)
Questions
- Is there a way to have 11ty + Netlify "share" the main domain? Normally, you will see things like https://digitalocean.com for marketing pages and then to login, you go to another URL https://cloud.digitalocean.com
- This is what we are trying to avoid
- So what you would want to do is make Nginx (or the application behind Nginx) know to send some paths to 11ty + Netlify, example
- Use
location
directive - SEO-friendly public pages for example /about, /privacy, /terms, /contact all should go to 11ty + Netlify
- Certain paths should also go to 11ty + Netlify for example /faq/, /public/
- All other URIs would go into the application code like it is now (right now, even the above URLs go into the application code)
- Use
Not sure if this is even possible or if there are alternate ways others have set this up as this seems too complex but I assume is probably a common use case for headless CMS
Solution 1:[1]
Instead of thinking about having your application handle all requests and forward them to Netlify, it might be easier (and more beneficial performance-wise) to have Netlify handle all requests and proxy other URLs to your server.
If you're using Netlify, they offer a rewrites/proxies service that can proxy certain paths to another server. By default, it will check if that path exists on Netlify (generated by 11ty) and serve anything that exists. We can take advantage of this by only generating our static assets with 11ty (/about, /privacy, etc) and have Netlify send everything else to your server.
Create a _redirects
file in your project root:
/* https://api.example.com/:splat 200
Make sure that other redirects you add go BEFORE this declaration. You can also use configure redirects with the Netlify configuration file netlify.toml
if you prefer that.
In the case of static assets, Netlify will also cache assets from your server on their CDN if you set proper caching headers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | person_v1.32 |