Closed charlyschulte closed 1 year ago
update: rtfm, the error dissapeared by not using localhost, instead using the url provided by the library as a return value when starting the server. then i´ve got an 404, this was fixed by copying the files into the DocumentDirectoryPath. by using the function in readme.
hopes it helpes anyone with the same problem
@birdofpreyru i have updated the function in your readme, maybe it can help:
async function prepareAssets() {
if(Platform.OS!=="android"){
return ${RNFS.DocumentDirectoryPath}/webroot
;
}
const targetWebrootPathOnDevice = ${RNFS.DocumentDirectoryPath}/webroot
;
// It is use-case specific, but in general if target webroot path exists // on the device, probably these assets have been extracted in a previous // app launch, and there is no need to extract them again. However, in most // locations these extracted files won't be delected automatically on // the apps's update, thus you'll need to check it and act accordingly, // which is abstracted as needsOverwrite() function in the condition. const alreadyExtracted = await RNFS.exists(targetWebrootPathOnDevice);
// TODO: Give an example of needsOverwrite(), relying on app version // stored in local files. Maybe we should provide with the library // an utility function which writes to disk a version fingerprint of // the app, thus allowing to detect app updates. For now, have // a look at the example project in the repo, which demonstrates more // realistic code. if (alreadyExtracted) await RNFS.unlink(targetWebrootPathOnDevice); // TODO: Careful here, as on platforms different from Android we do not // need to extract assets, we also should not remove them, thus we need // a guard when entering this clean-up / re-extract block.
// This function is a noop on other platforms than Android, thus no need // to guard against the platform. await extractBundledAssets(targetWebrootPathOnDevice, 'webroot'); return RNFS.MainBundlePath + '/webroot';
}
Well, glad you resolved it. I all sounds like a conflict between the server and firebase notification service over the port to listen on. Probably some misconfiguration on your side, or, I guess, when relying on the automatic selection of an open port by the server, there is some chance that between the server testing a port is available and it occupying that port, another service may jump in and seize that port.
That part of README refers to the Android usecase only, and it indeed should be updated. You better adopt a version from the example: https://github.com/birdofpreyru/react-native-static-server/blob/3bd511dbb70bb3fc18b7b346af0db9a83c6602f8/example/src/App.tsx#L43-L110
i have found another problem. After building the library with android and macos. the app starts without a problem, as long as i dont add the firebase notification library (https://rnfirebase.io/) you have to insert: classpath 'com.google.gms:google-services:4.3.15' into /android/build.gradle and apply plugin: 'com.google.gms.google-services' // <- Add this line into /android/app/build.gradle
if i do these steps, the webserver no longer starts up and i get this error: Encountered an error loading page {"canGoBack": false, "canGoForward": false, "code": -6, "description": "net::ERR_CONNECTION_REFUSED", "loading": false, "target": 15, "title": "", "url": "http://localhost:8080/"}