fermyon / spin

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly.
https://developer.fermyon.com/spin
Apache License 2.0
5.47k stars 255 forks source link

Static assests like CSS and JS are not coming properly for SPIN application after deploying to cloud #2829

Closed kunjee17 closed 2 months ago

kunjee17 commented 2 months ago

Do any of the following links help with your problem?

Application Prerequisites Spin Build and Spin Up is Working Troubleshooting - Rust NA Cloud FAQ NA

If you still see a bug or problem, please let us know:

I have setup demo project here https://github.com/kunjee17/spin_cloud_test . Basically everything works without any issue. Even spin build and spin up also works. But as they say it works on my machine . When I deployed the application https://pi-health.fermyon.app/ html works but it looses css and js files. I did try to trouble shoot it, but unlike normal server I don't if that is possible to get into WASM to see if all files are there. More frustrating is that it works locally. Do let me know if any other thing is required from my end.

itowlson commented 2 months ago

Thank you for the detailed repro and sorry you're running into this. I was able to clone your repository and build and run it. When I deployed it, the CSS and JS seemed to be working correctly - certainly what I see is more styled than what I see at your URL. See:

https://test-ltovrbcl.fermyon.app/

Is it possible that something wasn't built quite right at the time you ran spin deploy, and something could have been missing from the dist directory at the time you deployed? I am not sure how this could be, though, since it was working locally for you at the time of deployment.

Are there any logs in the Fermyon Cloud admin screen?

Is it practical for you (if you haven't tried this already) to delete the app out of Fermyon Cloud and redeploy?

kunjee17 commented 2 months ago

Hard Reset

dist folder

I have tried running a dist folder separately and it works. So, no issues there.

spin build

spin up

Spin up works just fine. All three urls \, \api and \admin works.

spin deploy

Creates new application and still the same issue. https://pi-nvifxthv.fermyon.app/ . There is no logs as of now.

My guess

itowlson commented 2 months ago

Aha, thanks. Yes, this is a bug in our Windows plugin, and I can reproduce it.

If you have WSL or Mac handy, that ought to work (I was using WSL). We'll look into this and get a fix out. Thanks for flagging this and thanks again for such a convenient repro case.

kunjee17 commented 2 months ago

@itowlson I just made it run with WSL. And then seen you comment :) . Thanks for help. I ll keep the issue open for ref. But for now all is good. Thanks a lot.

itowlson commented 2 months ago

Seems to be a specific issue with nested subdirectories under Windows. The top level works fine (index.html in this case) but the assets directory isn't behaving. It looks like during push we are snapshotting the OS path to the file (assets\whatever.js); and so when we run in Cloud, the assets/whatever.js path doesn't map correctly. It works in spin up because then it's running on Windows and the filesystem layer handles both types of separator.

I can reproduce the same behaviour by pushing an app from Windows to a registry, and then doing a spin up --from-registry from WSL. Here is (the relevant portion of) the lockfile snapshotted into the OCI image:

image

(Yes I know I use stupid filenames for bug repros.)

On the other hand I can't access the file using a URL with a backslash in it either so maybe there is more going on...

kunjee17 commented 2 months ago

@itowlson It seems thing boils down to how paths should be there. Windows and Linux always took different route and it is always headache for developers to monkey patch things.

My first guess was cloud might not be allowing _ or - like things. But when you successfully push from your end then my guess what windows being windows again. And I was kind of right. But I thought spin just forgot to include files or something like that. I am still new to spin so I actually doesn't know to ssh deployed files.

But do let me know. happy to help any way possible to solve this and even other issues.