Running the project
- In one terminal window
$ python app.py dev
- In a second (if you are working on sass styles)
$ compass watch -c config.rb
Test Author Login
- email: [email protected]
- pass: Jake1234
Unittest
- Run
$ python run_tests.py
HTTP static file server for React Native
License: MIT License
Running the project
$ python app.py dev
$ compass watch -c config.rb
Test Author Login
Unittest
$ python run_tests.py
Original issue in NanoHttpd repo
I have RN app with WebView
that shows local stored files via react-native-static-server
. I run and stop server every time when WebView
is created. On iOS it works fine, but on Android server returns 304 response like described in original issue.
Can you implement any solutions for this problem? May be it can be a some flag or property of server that turns on and off it solution. Thank you!
Hi and thanks for this nice RN module!
This might be stupid question, but I wonder if it's possible to serve html/js/css-files from assets? (in Android)
So if I use filesystem, I'm using file:///android_asset/web/index.html
-uri in WebView
but I would like to use http://127.0.0.1:8080
as an uri with react-native-static-server serving files from that assets path.
If it's not possible to do that, what is the best way to copy files from assets to /data/data/com.xxx/files/whatever
?
This seems to be very simple with iOS where you can just use "MainBundlePath"/whatever
as a path and put your html/js/css-files in that folder.
Hello, how can in android www be added to the project
INTERNAL ERROR: given path is not a directory (/data/user/0/com.reactappdemo/files/www).
Is there any way to redirect all requests to index.html, for example? Or any other approach to this?
I installed the server
as suggested and linked it automatically.
I then try to run the minimal example
import StaticServer from 'react-native-static-server';
let server = new StaticServer(8080);
server.start().then((url) => {
console.log("Serving at URL", url);
});
However, that gives me this error as soon as I start the App on Android (it works on iOS):
name == null
Screenshot error
It points me to FPStaticServerModule.java
, line 101 which says
www_root = new File(this.reactContext.getFilesDir(), root);
I am not sure what to make of it.
I checked if the linking was correct and the only difference between automatic-
and manual
linking is that the docs
say
"add this line import com.reactlibrary.FPStaticServerPackage;
in android/app/src/main/java/[...]/MainActivity.java" while the automatic linking inserts import com.futurepress.staticserver.FPStaticServerPackage;
into MainApplication.java. Looking at the MainApplication.java file I see many other libraries linked there, so I assume thats correct. In MainApplication.java I tried exchanging the line import com.futurepress.staticserver.FPStaticServerPackage;
as thedocs
suggest with import com.reactlibrary.FPStaticServerPackage;
. No luck.
The error was reported here too #5
yarn: 1.0.2
react-native-cli: 2.0.1
react-native: 0.48.3
npm: 5.3.0
Where could the error come from? I tried installing the sever on a fresh initialized project and got the same error.
Hi Thanks for the module
Is their any way to create a https server
as I would like to open a web view with a link to open locally stored manifest file that can install an app.
itms-services://?action=download-manifest&url=https://127.0.0.1:8080/manifest.plist
for example
Thanks in advance.
:0)
I did some tests and right now there's no way to point the StaticServer to a 'www_root' on the assets folder on Android. I think storing the static files as assets is a straightforward way, but I couldn't find a way to make it work.
Any ideas?
p.s. RNFS.DocumentDirectoryPath is not where the assets are stored
Hey !
I've an issue when i'm building on a IOS device (iPhone 6s Plus) :
The server start at (null)://(null):(null) so nothing works.
The config (works great in simulator) :
let server = new StaticServer(8080, RNFS.DocumentDirectoryPath); server.start().then((url) => { alert('Server started at ' + url) });
Note : it happens only if WIFI is turned off
Any idea ?
Regards
Is there a way to allow cross domain requests? I have tried to set Access-Control-Allow-Origin but not found how do that. is there any other way?
// everything is the latest version for today
npm install --save react-native-static-server
react-native link react-native-static-server
react-native android-run
Loading dependency graph, done.
Bundling index.js
[development, non-minified] 0.0% (0/1), failed.
error: bundling failed: ambiguous resolution: module C:\Users\unknown\test\index.js
tries to require react-native
, but there are several files providing this module. You can delete or fix them:
C:\Users\unknown\test\node_modules\react-native-static-server\node_modules\react-native\package.json
C:\Users\unknown\test\node_modules\react-native\package.json
Do you know what could be the root cause of the problems?
Thank you,
Heya
Just trying to build this into my project. I'm getting missing symbols "_deflate", "_inflate", "_defaultEnd" and a few others.
Is this from zlib ? How should I link them in ?!
Thanks!
Jonah
First, thanks the lib π
I'm having some issues trying to access to the index.html
from the browser, everything seems to be working fine but I can't get it running pointing to my www
folder, I know there is not issue with the lib, the error is This 192.168.1.36 page canβt be found
because locally inside the app, the folder where my index file should be, not exists, so I'm passing the path
like this:
let path = fs.DocumentDirectoryPath + '/embeded'
console.log(path)
let server = new StaticServer(9191, path)
server.start().then((url) => {
console.log("Serving at URL", url);
})
But when I check inside the final "temporal folder" in the simulator, I don't see the embeded
folder, so is not finding the index.html
because the folder do not exists.
I already tried adding the folder to my xcode project, trying that the folder gets created inside the bundle app, but didn't work:
This is a cry for help... any advice?
Thanks
Linker command failed with exit code 1 (use-v to see invocation) may occur when react-native-static-server is used in conjunction with realm, possibly because of duplicate names. How to solve this problem?
Hi
Does it require main Queue or not? getting react native warning
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
While starting the server FPStaticServer
is undefined, hence server is not started.
Using [email protected]
Hi there,
On Android, I am trying to host a staic server on localhost, i have remote debugging enabled, but i also tried with it disabled.
Is there anyway to force it on localhost? Is this only happening cuz im in dev mode?
On a physical IOS ipad, localhost with port 8081, 8082, 8083 and with {keepAlive: true} and the asset I wanna serve doesn't open in safari. Is this because of debug mode. Will it work after producing a signed build. Any suggestions of this is appreciated. Thanks.
Been using your plugin for a while and love it, but I've ran into a big problem. When all internet / wifi has been turned on I cannot start the server.
Error: StaticServer could not start
Any ideas how I can get around this?
Thanks
The instruction from here say:
Open up
android/app/src/main/java/[...]/MainActivity.java
Addimport com.futurepress.staticserver.FPStaticServerPackage;
to the imports at the top of the file
Addnew FPStaticServerPackage()
to the list returned by thegetPackages()
method
However, imports are usually done in android/app/src/main/java/[...]/MainApplication.java
from what I've seen with other RN projects that need linking. Also, the getPackages
method only exists in MainApplication.java
.
Hi
Can you please expose server url property so when server is already running, we can access the url without starting it again.
// example use case
let server = new StaticServer(8080, path, { keepAlive: true });
if (!server.running) {
var url = await server.start();
console.log("Server URL", url);
} else {
// get server url
var url = server.serverUrl;
}
One more question => Should we have only single instance of server with in the app? What is server initialization recommendation?
I am facing this issue in android, when I try to start the server , but In IOS it returns url.
After installing react-native-static-server I keep getting this error.
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugApk'.
Configuration with name 'default' not found.
I installed react-native-static-server
before the keepAlive
option was available. I tried yarn update react-native-static-server
, which did not update to the version that is on git. Is it known to yarn
that there is a new version of this nice library out there?
keepAlive works fine when the app is in the background, however when the device is locked or goes into standby the server is no longer running in the background, or when the app is put into the foreground again.
Not sure if keepAlive is meant to support this or not, I am considering starting the server again manually once the app is 'active' as a work around for now.
Are these folders related to GCDWebServer, if not please remove them from iOS folder
Hi,
My app works correct on IOS but fails on Android. The assets have been downloaded and stored onto the device, that are located here /data/user/0/com.springboard/files/11 and then served via the Static Server.
The path the assets are download to is RNFS.DocumentDirectoryPath + '/11'
RNFS.exists(RNFS.DocumentDirectoryPath + '/11').then((result)=> {
//Check files are there..
if(result){
webserver = new StaticServer(8080, RNFS.DocumentDirectoryPath + '/11/index.html')
webserver.start().then((url) => {
dispatch({type: types.APP_VISABILITY, payload: url})
})
}
})
But when the web view is loaded it seems to have the error
"net::ERR_CONNECTION_REFUSED"
Any ideas?
Does it support upload files? As I know, GCDWebserver support uploading file
Hi,
I am using React Native 0.57.5 and react-native-static-server 0.3.0.
The constructor of the rn static server runs without problems. When the code reaches to call the native module FPStaticServer.start
it throws an exception saying that the FPStaticServer object is undefined.
I guess there is a problem in the native module link with the javascript.
Anyone with similar problems or a solution to this one?
Hi
I found this issue of server already running looks difficult to keep track of server status on RN.
so its better to return serverUrl if server is already started, rather than throw error or warning
// in FPStaticServer.m
// instead of these lines
if(_webServer.isRunning != NO) {
NSError *error = nil;
reject(@"server_error", @"StaticServer is already up", error);
return;
}
// return server url
if(_webServer.isRunning != NO) {
RCTLog(@"server already starting: %@", self.url);
resolve(self.url);
return;
}
and in index.js
// remove commented lines, as it will return the server url if its already running
start() {
// if( this.running ){
// return console.warn('StaticServer already running');
// }
this.started = true;
this.running = true;
if (!this.keepAlive && (Platform.OS === 'android')) {
AppState.addEventListener('change', this._handleAppStateChange.bind(this));
}
return FPStaticServer.start(this.port, this.root, this.localOnly, this.keepAlive);
}
also same thing for stop, don't throw the warning if its not running, as it will do nothing in FPStaticServer.m
// please remove commented lines
stop() {
// if( !this.running ){
// return console.warn('StaticServer not running');
// }
this.running = false;
return FPStaticServer.stop();
}
also better not keep track of running status in index.js, let FPStaticServer.m handle it.
Let me know your comments, happy to submit a PR if you are ok with above changes
Every time I add react-native-static-server into my project I got the error: bundling failed: "Unable to resolve module AccessibilityInfo
.
I'm using [email protected], tried everything, nothing works...
how to upload file to app static folder
Removing {localOnly: true} option on an IPhone 6 - IOS 11.2 simulator or even on an android simulator/physical device doesn't seem to open the files I wanna serve in safari or chrome or any browser, but it can serve the files through a webview on the app itself. Correct me if I'm wrong but is this what removing this option expected. Any suggestions on how to proceed next is appreciated. Thanks!
Please, add licence file
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/home/upyun/impress-webview/android/app/src/main/java/com/impress_webview/MainApplication.java:17: error: package com.reactlibrary does not exist
import com.reactlibrary.FPStaticServerPackage;
^
/home/upyun/impress-webview/android/app/src/main/java/com/impress_webview/MainApplication.java:33: error: cannot find symbol
new FPStaticServerPackage(),
^
symbol: class FPStaticServerPackage
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
Imagine I have a function within a component
export default class Test extends Component {
...
_startServer = () => {
server
.start()
.then((localServer) => {
this.setState({
serverRunning: true,
localServer: localServer
})
});
}
_stopServer = (refToServer) => {
refToServer.stop();
}
...
render() {
return (
<TouchableOpacity
onPress={() => this._startServer()} />
<TouchableOpacity
onPress={() => this._stopServer(??)} />
)
}
}
How would I pass the _stopServer()
function the reference to the server that it knows, what to stop?
HI, I found this bug in my app I can not overcome it for 2 days:
This is the link for the question open on stackoverflow.
You know how to solve it?
Thank you very much and good job.
Seems that .git
-folder is added to npm registry and I think it shouldn't be there.
Now this package causes react-native-static-server: Appears to be a git repo or submodule
-error when try to perform react-native-git-upgrade
and react-native-static-server
is installed from npm registry.
Solution is to manually remove node_modules/react-native-static-server/.git
-folder or install package directly from github.
Hi
Thanks for the great library.
When the app is in background the server is not running, i have started with below setting
let server = new StaticServer(8080, path, { keepAlive: true });
after going through the GCDWebServer documentation, we need to set GCDWebServerOption_ConnectedStateCoalescingInterval
[options setObject:@2.0 forKey:GCDWebServerOption_ConnectedStateCoalescingInterval];
can you please provide this option to set duration to keep running when app is in background
I use this react-native-fs and react-native-static-server storage network to download the picture, but I can't access what I should do @frangeris @fchasen @JakeHartnell @sampsasaarela @AJRenold
Please help me, thank you.
Hello and thanks for a great library. It works fantastic.
I am just curious if it is somehow possible to allow the server to run while the app is in the background. I am using the library for redirection purposes, so the user opens a browser which then opens the localhost where my static file is. The problem is that as fast as I leave the app, the server shuts down.
Thanks in advance.
Hi
This is a suggestion,
Too many conditions check in constructor, my suggestion below
let server = new StaticServer({port: 8080, localOnly : true, keepAlive : true });
class StaticServer {
constructor(opts) {
if(opts)
{
this.port = `${opts.port}` || PORT;
this.root = opts.root || ROOT;
this.localOnly = opts.localOnly || false;
this.keepAlive = opts.keepAlive || false;
}
else{
this.port = PORT;
this.root = ROOT;
this.localOnly = false;
this.keepAlive = false;
}
}
....
}
let me know your feedback
Build fails on a fresh install of React Native 0.56 with react-native-static-server. Seems like resources are missing.
:react-native-static-server:preBuild UP-TO-DATE
:react-native-static-server:preReleaseBuild UP-TO-DATE
:react-native-static-server:checkReleaseManifest
:react-native-static-server:preDebugAndroidTestBuild UP-TO-DATE
:react-native-static-server:preDebugBuild UP-TO-DATE
:react-native-static-server:preDebugUnitTestBuild UP-TO-DATE
:react-native-static-server:preReleaseUnitTestBuild UP-TO-DATE
:react-native-static-server:prepareAndroidArchLifecycleRuntime100Library
:react-native-static-server:prepareComAndroidSupportAnimatedVectorDrawable2610Library
:react-native-static-server:prepareComAndroidSupportAppcompatV72610Library
:react-native-static-server:prepareComAndroidSupportSupportCompat2610Library
:react-native-static-server:prepareComAndroidSupportSupportCoreUi2610Library
:react-native-static-server:prepareComAndroidSupportSupportCoreUtils2610Library
:react-native-static-server:prepareComAndroidSupportSupportFragment2610Library
:react-native-static-server:prepareComAndroidSupportSupportMediaCompat2610Library
:react-native-static-server:prepareComAndroidSupportSupportV42610Library
:react-native-static-server:prepareComAndroidSupportSupportVectorDrawable2610Library
:react-native-static-server:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library
:react-native-static-server:prepareComFacebookFrescoDrawee190Library
:react-native-static-server:prepareComFacebookFrescoFbcore190Library
:react-native-static-server:prepareComFacebookFrescoFresco190Library
:react-native-static-server:prepareComFacebookFrescoImagepipeline190Library
:react-native-static-server:prepareComFacebookFrescoImagepipelineBase190Library
:react-native-static-server:prepareComFacebookFrescoImagepipelineOkhttp3190Library
:react-native-static-server:prepareComFacebookReactReactNative0560Library
:react-native-static-server:prepareComFacebookSoloaderSoloader030Library
:react-native-static-server:prepareOrgWebkitAndroidJscR174650Library
:react-native-static-server:prepareReleaseDependencies
:react-native-static-server:compileReleaseAidl
:react-native-static-server:compileReleaseNdk NO-SOURCE
:react-native-static-server:compileLint
:react-native-static-server:copyReleaseLint NO-SOURCE
:react-native-static-server:compileReleaseRenderscript
:react-native-static-server:generateReleaseBuildConfig
:react-native-static-server:generateReleaseResValues
:react-native-static-server:generateReleaseResources
:react-native-static-server:mergeReleaseResources
:react-native-static-server:processReleaseManifest
:react-native-static-server:processReleaseResources
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:4: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:15:21-54: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v24/values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/home/pvl/workspace/repo/htone/htone/node_modules/react-native-static-server/android/build/intermediates/res/merged/release/values-v26/values-v26.xml:15: error: Error: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
:react-native-static-server:processReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-static-server:processReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.