After some research I undestood that it is possibile to deploy a website with Astro on Netlify with Server Side Rendering.
Reading the documentation it seems it is also possible to use Netlify On-Demand builder to build pages on demand and then cache them on the CDN.
I tried to implement this feature but it doesn’t seem to work. Can somebody knows why?
Here is my code:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import netlify from "@astrojs/netlify/functions";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: netlify({
builders: true,
})
});
// netlify.toml
[build]
command = "yarn build"
publish = "dist"
// src/pages/index.astro
---
import Layout from "../layouts/Layout.astro";
const response = await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(7);
}, 2000)
});
---
<Layout title="Welcome to Astro">
<main>MAIN {response}</main>
</Layout>
The setTimeout
is for emulating an async
method that takes some times.
After deploying with:
ntl deploy --prod
I see the page waiting 2 seconds before delivering the HTML.
However I would expect the Netlify On-Demand Builder to cache it and then not wait 2 seconds anymore.
What am I doing it wrong?