1
1
# React Native Static Server
2
2
3
+ <!-- Status Badges & Important Links -->
4
+
3
5
[ ![ Latest NPM Release] ( https://img.shields.io/npm/v/@dr.pogodin/react-native-static-server.svg )] ( https://www.npmjs.com/package/@dr.pogodin/react-native-static-server )
4
6
[ ![ NPM Downloads] ( https://img.shields.io/npm/dm/@dr.pogodin/react-native-static-server.svg )] ( https://www.npmjs.com/package/@dr.pogodin/react-native-static-server )
5
7
[ ![ CircleCI] ( https://dl.circleci.com/status-badge/img/gh/birdofpreyru/react-native-static-server/tree/master.svg?style=shield )] ( https://app.circleci.com/pipelines/github/birdofpreyru/react-native-static-server )
6
8
[ ![ GitHub Repo stars] ( https://img.shields.io/github/stars/birdofpreyru/react-native-static-server?style=social )] ( https://github.com/birdofpreyru/react-native-static-server )
7
9
[ ![ Dr. Pogodin Studio] ( https://raw.githubusercontent.com/birdofpreyru/react-native-static-server/master/.README/logo-dr-pogodin-studio.svg )] ( https://dr.pogodin.studio/docs/react-native-static-server )
8
10
9
- <!-- Misc links -->
10
- [ GCDWebServer ] : https://github.com/swisspol/GCDWebServer
11
- [ NanoHttpd ] : https://github.com/NanoHttpd/nanohttpd
11
+ <!-- Misc references -->
12
+
13
+ [ @dr.pogodin/react-native-fs ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs
14
+ [ copyFileAssets() ] : https://github.com/birdofpreyru/react-native-fs?tab=readme-ov-file#copyfileassets
15
+ [ Error ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
16
+ [ Example App ] : https://github.com/birdofpreyru/react-native-static-server/tree/master/example
17
+ [ Expo ] : https://expo.dev
18
+ [ getDeviceType() ] : https://www.npmjs.com/package/react-native-device-info#getDeviceType
12
19
[ Lighttpd ] : https://www.lighttpd.net
20
+ [ MainBundlePath ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs#mainbundlepath
21
+ [ mod_alias ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_alias
22
+ [ mod_rewrite ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_rewrite
23
+ [ mod_webdav ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_webdav
13
24
[ New Architecture ] : https://reactnative.dev/docs/the-new-architecture/landing-page
14
25
[ Old Architecture ] : https://reactnative.dev/docs/native-modules-intro
15
26
[ Promise ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
27
+ [ react-native-device-info ] : https://www.npmjs.com/package/react-native-device-info
16
28
[ React Native ] : https://reactnative.dev
29
+ [ TemporaryDirectoryPath ] : https://github.com/birdofpreyru/react-native-fs?tab=readme-ov-file#temporarydirectorypath
30
+ [ WebDAV ] : https://en.wikipedia.org/wiki/WebDAV
31
+
32
+ <!-- The regular README content starts here -->
17
33
18
34
Embedded HTTP server for [ React Native] applications for Android, iOS, Mac (Catalyst),
19
35
and Windows platforms. Powered by [ Lighttpd] server, supports both [ new] [ New Architecture ]
@@ -42,23 +58,6 @@ and [old][Old Architecture] RN architectures.
42
58
43
59
[ ![ Logo] ( https://avatars.githubusercontent.com/u/71085569?s=36 )] ( https://github.com/Lumentric )
44
60
45
- <!-- links -->
46
- [ @dr.pogodin/react-native-fs ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs
47
- [ Error ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
48
- [ example app ] : https://github.com/birdofpreyru/react-native-static-server/tree/master/example
49
- [ Expo ] : https://expo.dev
50
- [ OLD-README.md ] : https://github.com/birdofpreyru/react-native-static-server/blob/master/OLD-README.md
51
- [ getDeviceType() ] : https://www.npmjs.com/package/react-native-device-info#getDeviceType
52
- [ MainBundlePath ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs#mainbundlepath
53
- [ mod_alias ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_alias
54
- [ mod_rewrite ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_rewrite
55
- [ mod_webdav ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_webdav
56
- [ react-native-device-info ] : https://www.npmjs.com/package/react-native-device-info
57
- [ react-native-fs ] : https://www.npmjs.com/package/react-native-fs
58
- [ React Native ] : https://reactnative.dev
59
- [ TemporaryDirectoryPath ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs#temporarydirectorypath
60
- [ WebDAV ] : https://en.wikipedia.org/wiki/WebDAV
61
-
62
61
## Content
63
62
64
63
- [ Getting Started] ( #getting-started )
@@ -87,8 +86,8 @@ and [old][Old Architecture] RN architectures.
87
86
- [ .state] &mdash ; Holds the current server state.
88
87
- [ .stopInBackground] &mdash ; Holds ` stopInBackground ` value provided to
89
88
[ constructor()] .
90
- - [ extractBundledAssets()] &mdash ; Extracts bundled assets into a regular folder
91
- (Android-specific).
89
+ - ~~ [ extractBundledAssets()] &mdash ; Extracts bundled assets into a regular folder
90
+ (Android-specific).~~
92
91
- [ getActiveServer()] &mdash ; Gets currently active, starting, or stopping
93
92
server instance, if any, according to the TS layer data.
94
93
- [ getActiveServerId()] &mdash ; Gets ID of the currently active, starting, or
@@ -108,7 +107,7 @@ and [old][Old Architecture] RN architectures.
108
107
109
108
- ** Note:**
110
109
111
- - This library's repository includes [ Example App] [ example app ] .
110
+ - This library's repository includes [ Example App] .
112
111
Have a look, try to build it, in addition to following the instructions
113
112
below.
114
113
@@ -195,7 +194,7 @@ and [old][Old Architecture] RN architectures.
195
194
(`com.apple.security.network.server` entitlement).
196
195
- If you bundle inside your app the assets to serve by the server,
197
196
keep in mind that in Mac Catalyst build they' ll end up in a different
198
- path, compared to the regular iOS bundle (see [example app ]): \
197
+ path, compared to the regular iOS bundle (see [Example App ]): \
199
198
iOS: " [MainBundlePath]` /webroot` " ; \
200
199
Mac Catalyst: " [MainBundlePath]` /Content/Resources/webroot` " .
201
200
@@ -309,21 +308,24 @@ outside platform-specific sub-folders.
309
308
- On Android the server cannot access bundled assets as regular files, thus
310
309
before starting the server to serve them, these assets should be extracted
311
310
into a folder accessible to the server (_e.g._ app' s document folder).
312
- To facilitate it, this library provides [extractBundledAssets ()] function.
313
- You want to use it in this manner :
311
+ You can use [copyFileAssets ()] function from [@dr.pogodin/react-native-fs]
312
+ library (v2.24.1 and above) :
314
313
```jsx
315
314
// TODO: To be updated, see a better code inside the example app.
316
315
316
+ import { Platform } from ' react-native' ;
317
+
317
318
import {
319
+ copyFileAssets,
318
320
DocumentDirectoryPath,
319
321
exists,
320
322
resolveAssetsPath,
321
323
unlink,
322
324
} from ' @dr.pogodin/react-native-fs' ;
323
325
324
- import {extractBundledAssets} from ' @dr.pogodin/react-native-static-server' ;
325
-
326
326
async function prepareAssets() {
327
+ if (Platform.OS !== ' android' ) return;
328
+
327
329
const targetWebrootPathOnDevice = resolveAssetsPath(' webroot' );
328
330
329
331
// It is use-case specific, but in general if target webroot path exists
@@ -348,7 +350,7 @@ outside platform-specific sub-folders.
348
350
349
351
// This function is a noop on other platforms than Android, thus no need
350
352
// to guard against the platform.
351
- await extractBundledAssets(targetWebrootPathOnDevice, ' webroot' );
353
+ await copyFileAssets( ' webroot' , targetWebrootPathOnDevice );
352
354
}
353
355
354
356
// " webroot" assets have been extracted into the target folder, which now
@@ -833,6 +835,16 @@ server.stopInBackground: boolean;
833
835
Readonly property. It holds `stopInBackground` value provided to [constructor()].
834
836
835
837
### extractBundledAssets()
838
+
839
+ **DEPRECATED!** _Use instead [copyFileAssets()] from
840
+ the [@dr.pogodin/react-native-fs] library v2.24.1 and above —
841
+ it does the same job in a more efficient way (it is implemented entirely
842
+ in the native layer, thus does not incur the overhead of recurrent
843
+ communication between the native and JS layers during the operation)._
844
+
845
+ _The [extractBundledAssets()], with its original implementation, will be kept
846
+ around for backward compatibility, but it will be removed in future!_
847
+
836
848
[extractBundledAssets()]: #extractbundledassets
837
849
```ts
838
850
import {extractBundledAssets} from ' @dr.pogodin/react-native-static-server' ;
0 commit comments