birdofpreyru/react-native-static-server

Improve documentation for assets bundling for iOS, and `resolveAssetsPath()`

belyylis opened this issue · 6 comments

Hi all! I created a game folder in the assets folder in the root of the project.
I did everything as in the instructions, but it gives me a 404 error. I tried to build an example, but got an error. I copied the code from App.tsx, but I still get 404. It is clear that the server is running, could you give more precise instructions on how to find the file? Checked on iOS. Added files to Xcode.

I found an indication of where the files were sent, it is not the same as when calling resolveAssetsPath

Hey @belyylis , do I get it as you have solved the problem? :) So, what was it? resolveAssetsPath() is a very simple function you can check in https://github.com/birdofpreyru/react-native-static-server/blob/master/src/utils.ts — it just assumes the base path for bundled assets in a platform-dependent manner, and adds it as a prefix to the relative path you gave, if it was relative. It works if you exactly followed the asset bundling as described in README (https://github.com/birdofpreyru/react-native-static-server/tree/master#bundling-in-server-assets-into-an-app-statically) and I guess it was just somewhat off if you placed your files in the root of your project? I surely can improve something in its behavior or documentation, if you tell, what exactly would be helpful?

I add the folder name to the method ('games'). The path in the console is correct ...NAME.app/games. But in fact index.html lies a level higher. In ...NAME.app

image

Apparently I understood something wrong, there was the first option. Everything worked, but only in dev mode.
Now Xcode won't build. And on Android there is a white screen.
The dev works everywhere.

I add the folder name to the method ('games'). The path in the console is correct ...NAME.app/games. But in fact index.html lies a level higher. In ...NAME.app

Ok, I have to re-check what is written in README once I have Mac machine around. In the example app, and the README is supposed to describe the same, test assets are kept inside /assets/webroot folder of the codebase, and I am not sure now, when adding it into Xcode project whether I was selecting the webroot folder itself, as README says, or maybe the parent assets folder. Anyway, the way I did it was to land the assets into ...NAME.app/webroot, so when it is served by the server, it does not expose anything else beside the assets (as in your case it would expose everything inside app bundle).

I am not sure now, but probably I selected Create groups, and did not opt to copy files. Anyway, if it works for you in dev mode, but not in the release mode... my first guess would be there is some other problem, not related to the static server setup.

Ok, I did my best to improve instructions for static assets bundling into iOS apps. In general, as it was described before was correct. I checked that Create folder references is the correct option for Added folders switch. I'll close this issue now, but feel free to re-open, or create a new one, if you still have troubles with it.