Skip to content

Commit 76cd09c

Browse files
authored
Merge pull request #9 from frangeris/master
Improve documentation (README.md)
2 parents 98833d1 + f39c361 commit 76cd09c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ server.start().then((url) => {
5454
server.stop();
5555
```
5656

57-
`StaticServer` serves from the document directory or takes an optional absolute path to serve from.
57+
`StaticServer` serves from the document directory (default) or takes an optional absolute path to serve from.
58+
5859
For instance, using [react-native-fs](https://github.com/johanneslumpe/react-native-fs) you can get the document directory and specify a directory from there.
5960

61+
#### Default (document directory)
62+
6063
```javascript
6164
import StaticServer from 'react-native-static-server';
6265
import RNFS from 'react-native-fs';
@@ -67,6 +70,30 @@ let path = RNFS.DocumentDirectoryPath + '/www';
6770
let server = new StaticServer(0, path);
6871
```
6972

73+
#### Custom folder (iOS)
74+
75+
##### Create the folder for static files
76+
77+
Create a folder in your project's top-level directory (usually next to your node_modules and index.js file), and put the files you want to access over http in there.
78+
79+
##### Add folder (static files) to XCode
80+
81+
This folder **must be added to XCode** so it gets bundled with the app.
82+
83+
In XCode, `Project Navigator` right click in the folder project → `Add files to "<project>"` → Select the static folder **and clic options (Uncheck copy items if needed, Create folder references)** so don't duplicate files → Clic Add.
84+
85+
When the app gets bundled, this folder will be next to the compiled app, so using `MainBundlePath` property from `react-native-fs` you can access to the directory.
86+
87+
```javascript
88+
import StaticServer from 'react-native-static-server';
89+
import RNFS from 'react-native-fs';
90+
91+
// path where files will be served from (index.html here)
92+
let path = RNFS.MainBundlePath + '/www';
93+
94+
let server = new StaticServer(0, path);
95+
```
96+
7097
If the server should only be accessible from within the app, set `localOnly` to `true`
7198

7299
```javascript

0 commit comments

Comments
 (0)