export default {
async fetch(req, env, ctx) {
// Cached response
let res = await caches.default.match(req);
if (res) return res;
// Fetch object from origin
let reqPath = new URL(req.url).pathname;
reqPath = reqPath.replace(/\/$/, ''); // Remove trailing slash
if (!reqPath.includes('.')) // Check file extension
reqPath += '/index.html'; // Default to index page
res = await fetch(env.ORIGIN + reqPath);
if (res.status === 404) // Object not found
res = await fetch(env.ORIGIN + '/404.html');
// Configure content cache
res = new Response(res.body, res);
const ttl = res.headers.get('content-type').startsWith('text')
? 14400 : 31536000; // Cache text 4 hours, 1 year default
res.headers.set('cache-control', 'public, max-age=' + ttl);
// Cache and return response
ctx.waitUntil(caches.default.put(req, res.clone()));
return res;
},
};I think for these cases everyone should be shooting for a static site. In which case it is: 1. Rent a vps 2. Buy a domain 3. Set up nginx or something else 4. Copy files to the right folder 5. Point a dns record to said server 6. Use certbot to get an ssl cert installed for you
It's not that hard really.
> if you are a business or an individual artist or creator
If you're in any of those categories you're probably already in a small fraction of the population.
And yes this would only work with tech savvy people. I was mostly responding to the idea that AWS would need to be involved.
For the non tech savvy there's WordPress and Wix, no?
There's still the usability thing, they're not made for non-techies. There's an assumption you'll use Git, etc. But there's no practical reason why Netlify CMS or similar couldn't handle everything.
These things are not the hard part.
- server (AWS? 10 optional services to config etc etc, config, updates etc)
- domain
- SSL cert
Are there solid providers who do it all-in-one? I pay one bill, get a domain, SSL certificate, renewed, and a managed, pre-configured Linux box, or even static hosting? Thinking of setting up a webpage for my consulting business and I'd rather not spend weeks fiddling with all this, or (shudder) use Wix.