svelte-adapter-azure-swa icon indicating copy to clipboard operation
svelte-adapter-azure-swa copied to clipboard

Deploying app with +server.ts or routes/[slug]/+page.svelte

Open maxmalynowsky opened this issue 1 year ago • 2 comments

I'm having some difficulty getting dynamic pages and server APIs provided by SvelteKit from working on Azure Static Web Apps. I have successfully deployed an app to CloudFlare Pages with adapter-auto and both features working there. When I deploy to Static Web Apps, both dynamic pages and server APIs give 404 errors when trying to access them. Only the +page.svelte with a +layout.ts containing export const prerender = true; are rendered.

I noticed that the demo app doesn't include either of these, would it be possible to add them so I can see what I might be doing wrong on my end? If neither of these are supported with the current adapter, that would be helpful to know as well.

maxmalynowsky avatar Dec 10 '23 20:12 maxmalynowsky

I just noticed that I'm missing the correct staticwebapp.config.json options in my custom config referenced in https://github.com/geoffrich/svelte-adapter-azure-swa/issues/1. Mentioning this could be helpful to add to the README!

maxmalynowsky avatar Dec 10 '23 21:12 maxmalynowsky

What else would you like to see mentioned in the README that isn't covered by the customStaticWebAppConfig docs?

PRs welcome!

geoffrich avatar Jan 03 '24 18:01 geoffrich

I'm a bit confused here - am at a similar sticking point re my /api directory with my routes.

Should I refactor to use only form actions? Or is it possible to tinker with customStaticWebAppConfig in order to get my current /api routes to work... not that clear to me. If that is possible, an example would be incredibly useful

jaycoolslm avatar May 26 '24 16:05 jaycoolslm

@jaycoolslm are you saying that you have other Azure functions under /api that you want to call? In that case, look into the apiDir option.

If you are still having trouble, please open a new issue with an example of what you're trying to do. I'll close this issue since the original post was resolved.

geoffrich avatar May 26 '24 18:05 geoffrich

Yes - exactly that.

So essentially all I need to do is rename '/api' e.g. to '/svelteApi' (so it doesn't cause the build error), and then pass in apiDir: '/svelteApi'?

And then set up host and package.json for that dir

jaycoolslm avatar May 27 '24 08:05 jaycoolslm

If you're getting a build error, that sounds like https://github.com/geoffrich/svelte-adapter-azure-swa/issues/89, which would be unrelated to the apiDir option.

It's hard to troubleshoot with fragments of information like this. Again, please open a new issue with a code repository showing what you're trying to do and I'll be able to provide better help.

geoffrich avatar May 28 '24 15:05 geoffrich