Skip to content

Improve Astro detection and add --caddy option - #171

Open
kylemclaren wants to merge 2 commits into
mainfrom
astro-detection-caddy
Open

kylemclaren wants to merge 2 commits into
mainfrom
astro-detection-caddy

Conversation

@kylemclaren

Copy link
Copy Markdown
Contributor

Changes

Astro detection

  • Detect astro in devDependencies too. Before, an app with astro only in devDependencies was a generic Node.js app, and the container ran node index.js.
  • Detect @astrojs/node in devDependencies too. Before, such an app was a static site, and nginx showed its default page.
  • When astro or @astrojs/node is in devDependencies of an SSR app, do not prune development dependencies. The server imports the adapter and its dependencies (for example server-destroy) at runtime.
  • With the node adapter in middleware mode, the build output is a handler for a custom server, not a server. The app is now not treated as SSR, so the container runs the start script. Before, the container ran node ./dist/server/entry.mjs, which exited at once.
  • Read outDir from astro.config.*. Before, a custom outDir caused the image build to fail, because /app/dist did not exist.
  • Read base from astro.config.* for static sites. The files are copied below the base path, so /docs/ serves the site. Before, all pages returned 404.

Static Astro sites with nginx

  • Add an nginx config with absolute_redirect off. Before, /about redirected to http://<host>/about/, which drops HTTPS and the port.
  • Add error_page 404 /404.html, so the site's own 404 page is served (for example Starlight's). Before, nginx showed its default 404 page.
  • Do not prune development dependencies in the build stage. The final image contains only the built files.

--caddy option

  • New --caddy option: serve static Vite and Astro sites with caddy:2-alpine instead of nginx. nginx stays the default.
  • For Astro, the Caddyfile also serves the site's 404 page. Caddy redirects are relative by default.
  • The image is approximately 93 MB, against approximately 240 MB for nginx.
  • --nginx-root does not change.

Tests

  • New unit tests: detection from devDependencies, middleware mode, outDir and base, and --caddy.
  • New fixtures: astro-config (outDir, base, astro in devDependencies), astro-middleware, astro-caddy and vite-caddy.
  • astro-static fixture updated for the nginx config.

These apps from create-astro build and start in Docker, and their pages, redirects and 404 pages give the expected responses:

  • minimal, basics, blog and starlight templates, with npm. minimal also with pnpm.
  • Static site with a custom 404 page, with nginx and with --caddy.
  • Static site with outDir, with base (nginx and --caddy), and with astro in devDependencies.
  • Node adapter with output: 'server', with the default output and an on-demand page, with @astrojs/node in devDependencies, and in middleware mode with a custom server.

- Detect astro and @astrojs/node in devDependencies.
- Read outDir and base from astro.config.
- Serve the site's 404 page and use relative redirects for static sites.
- Run the start script for the node adapter in middleware mode.
- Keep devDependencies for SSR when astro or the adapter is one.
- Add --caddy to serve static Vite and Astro sites with Caddy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant