-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to start server :-( #102
Comments
Same here, RN 0.63, can not get past this error |
working for me in RN 0.63.3, but I had to add second parameter in StaticServer, new StaticServer(3000, getWebResourcesPath()) function getWebResourcesPath() { I also copy my assets ( android\app\src\main\assets\www) to "DocumentDirectory" before I start StaticServer with this function... async function copyWWWBuildFiles(directory: string) { |
Mario, thanks so much for your solution here. It almost works for me. Unfortunately I am brand new to android development, and I can't quite figure out how to actually call that copyWWWBuildFiles function with a directory path that react native will understand. I tried using copyWWWBuildFiles('android/app/src/main/assets/www'); right after it was defined, but the iterator doesn't actually do anything. I only have one file in my 'android/app/src/main/assets/www' directory called test.html
Webview displays the text: I've also tried simply "www", "/www", "www/", and "/www/" as the target directory for copyWWWBuildFiles So after "jettifying?" the project, the www directory now shows up as an available asset.
|
@WeirdDNA you are right I also hardcoded RNFS.mkdir(RNFS.DocumentDirectoryPath + '/www'); in my code but forgot to mention it. Glad It works! |
Here is my code
import React , { useEffect, useState } from 'react';
import {
StyleSheet,
View,
Text,
Platform,
TouchableOpacity
} from 'react-native';
import StaticServer from 'react-native-static-server';
import RNFS from "react-native-fs";
const App = () => {
const [ url , setURL ] = useState(null);
let server = new StaticServer();
useEffect(()=>{
console.log("App Started");
},[])
const getPath = () => {
return Platform.OS === "android"
? RNFS.DocumentDirectoryPath
: RNFS.MainBundlePath;
}
const startServer = () => {
console.log("Start Called");
server.start().then( url => {
console.log("Server Started at : ",url);
setURL(url);
});
}
const stopServer = () => {
if (server && server.isRunning()) {
server.stop();
console.log("Server Stop");
}
}
return (
<>
{url!==null?url:""}
<TouchableOpacity onPress={()=>{startServer()}}>Start Server
<TouchableOpacity onPress={()=>{stopServer()}}>Stop Server
</>
);
};
const styles = StyleSheet.create({
url:{
alignItems:"center",
},
btn:{
flexGrow:1,
flexDirection:"row",
alignItems:"center",
justifyContent:"space-around"
}
});
export default App;
The text was updated successfully, but these errors were encountered: