Is there an easy way to serve an Astro site from Phoenix?

I have an Astro site with hundreds of pages. I want to serve those page from Astro, except for certain paths that I want to serve from Phoenix:

  • forum
  • api
  • static
  • websockets
  • and maybe a few other things

So any inbound request would first be served by a static file from Astro if it exists, but if a request comes for one of the Phoenix routes, Phoenix would handle it.

Symlinking Astro’s dist dir to Phoenix won’t work, because I need paths like / and /about/ to be served from Astro.

Phoenix didn’t like it when I removed priv/static/ and symlinked Astro’s dist dir to priv/static/:

[Error: ENOTDIR: not a directory, mkdir '../priv/static'] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'mkdir',
  path: '../priv/static'
}

I might be able to manually symlink every Astro directory to priv/static/ using a script, but I’m not sure if that’s a good idea.

Is there another way?

Or would it be better to put NGINX in front of both sites and route the requests that way?

1 Like