Skip to content

Commit 87c4961

Browse files
committed
Merge branch 'dev'
2 parents f77c555 + d01f8a8 commit 87c4961

File tree

6 files changed

+355
-233
lines changed

6 files changed

+355
-233
lines changed

README.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
# React Native Static Server
22

3+
<!-- Status Badges & Important Links -->
4+
35
[![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)
46
[![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)
57
[![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)
68
[![GitHub Repo stars](https://img.shields.io/github/stars/birdofpreyru/react-native-static-server?style=social)](https://github.com/birdofpreyru/react-native-static-server)
79
[![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)
810

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
1219
[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
1324
[New Architecture]: https://reactnative.dev/docs/the-new-architecture/landing-page
1425
[Old Architecture]: https://reactnative.dev/docs/native-modules-intro
1526
[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
1628
[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 -->
1733

1834
Embedded HTTP server for [React Native] applications for Android, iOS, Mac (Catalyst),
1935
and Windows platforms. Powered by [Lighttpd] server, supports both [new][New Architecture]
@@ -42,23 +58,6 @@ and [old][Old Architecture] RN architectures.
4258

4359
[![Logo](https://avatars.githubusercontent.com/u/71085569?s=36)](https://github.com/Lumentric)
4460

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-
6261
## Content
6362

6463
- [Getting Started](#getting-started)
@@ -87,8 +86,8 @@ and [old][Old Architecture] RN architectures.
8786
- [.state] &mdash; Holds the current server state.
8887
- [.stopInBackground] &mdash; Holds `stopInBackground` value provided to
8988
[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).~~
9291
- [getActiveServer()] &mdash; Gets currently active, starting, or stopping
9392
server instance, if any, according to the TS layer data.
9493
- [getActiveServerId()] &mdash; Gets ID of the currently active, starting, or
@@ -108,7 +107,7 @@ and [old][Old Architecture] RN architectures.
108107

109108
- **Note:**
110109

111-
- This library's repository includes [Example App][example app].
110+
- This library's repository includes [Example App].
112111
Have a look, try to build it, in addition to following the instructions
113112
below.
114113

@@ -195,7 +194,7 @@ and [old][Old Architecture] RN architectures.
195194
(`com.apple.security.network.server` entitlement).
196195
- If you bundle inside your app the assets to serve by the server,
197196
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]): \
199198
iOS: "[MainBundlePath]`/webroot`"; \
200199
Mac Catalyst: "[MainBundlePath]`/Content/Resources/webroot`".
201200
@@ -309,21 +308,24 @@ outside platform-specific sub-folders.
309308
- On Android the server cannot access bundled assets as regular files, thus
310309
before starting the server to serve them, these assets should be extracted
311310
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):
314313
```jsx
315314
// TODO: To be updated, see a better code inside the example app.
316315
316+
import { Platform } from 'react-native';
317+
317318
import {
319+
copyFileAssets,
318320
DocumentDirectoryPath,
319321
exists,
320322
resolveAssetsPath,
321323
unlink,
322324
} from '@dr.pogodin/react-native-fs';
323325
324-
import {extractBundledAssets} from '@dr.pogodin/react-native-static-server';
325-
326326
async function prepareAssets() {
327+
if (Platform.OS !== 'android') return;
328+
327329
const targetWebrootPathOnDevice = resolveAssetsPath('webroot');
328330
329331
// It is use-case specific, but in general if target webroot path exists
@@ -348,7 +350,7 @@ outside platform-specific sub-folders.
348350
349351
// This function is a noop on other platforms than Android, thus no need
350352
// to guard against the platform.
351-
await extractBundledAssets(targetWebrootPathOnDevice, 'webroot');
353+
await copyFileAssets('webroot', targetWebrootPathOnDevice);
352354
}
353355
354356
// "webroot" assets have been extracted into the target folder, which now
@@ -833,6 +835,16 @@ server.stopInBackground: boolean;
833835
Readonly property. It holds `stopInBackground` value provided to [constructor()].
834836
835837
### extractBundledAssets()
838+
839+
**DEPRECATED!** _Use instead [copyFileAssets()] from
840+
the [@dr.pogodin/react-native-fs] library v2.24.1 and above &mdash;
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+
836848
[extractBundledAssets()]: #extractbundledassets
837849
```ts
838850
import {extractBundledAssets} from '@dr.pogodin/react-native-static-server';

example/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
"windows": "react-native run-windows"
1313
},
1414
"dependencies": {
15-
"@dr.pogodin/react-native-fs": "^2.22.0",
15+
"@dr.pogodin/react-native-fs": "^2.24.1",
1616
"react": "18.2.0",
1717
"react-native": "0.73.2",
1818
"react-native-webview": "^13.6.4",
1919
"react-native-windows": "^0.73.4"
2020
},
2121
"devDependencies": {
22-
"@babel/core": "^7.23.7",
23-
"@babel/preset-env": "^7.23.8",
24-
"@babel/runtime": "^7.23.8",
25-
"@react-native/babel-preset": "^0.73.19",
26-
"@react-native/metro-config": "^0.73.3",
22+
"@babel/core": "^7.23.9",
23+
"@babel/preset-env": "^7.23.9",
24+
"@babel/runtime": "^7.23.9",
25+
"@react-native/babel-preset": "^0.73.20",
26+
"@react-native/metro-config": "^0.73.4",
2727
"@react-native/typescript-config": "^0.73.1",
2828
"babel-plugin-module-resolver": "^5.0.0",
29-
"metro-config": "^0.80.4",
29+
"metro-config": "^0.80.5",
3030
"pod-install": "^0.2.0"
3131
},
3232
"engines": {

example/src/App.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import {
1515

1616
import { Colors } from 'react-native/Libraries/NewAppScreen';
1717

18-
import { readFile, readFileAssets, unlink } from '@dr.pogodin/react-native-fs';
18+
import {
19+
copyFileAssets,
20+
readFile,
21+
readFileAssets,
22+
unlink,
23+
} from '@dr.pogodin/react-native-fs';
1924

2025
import { WebView } from 'react-native-webview';
2126

2227
import Server, {
2328
STATES,
24-
extractBundledAssets,
2529
resolveAssetsPath,
2630
} from '@dr.pogodin/react-native-static-server';
2731

@@ -109,7 +113,7 @@ export default function App() {
109113
}
110114
if (extract) {
111115
console.log('Extracting web server assets...');
112-
await extractBundledAssets(fileDir, 'webroot');
116+
await copyFileAssets('webroot', fileDir);
113117
}
114118
}
115119

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dr.pogodin/react-native-static-server",
3-
"version": "0.10.4",
3+
"version": "0.10.5",
44
"description": "HTTP static file server for React Native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -50,17 +50,17 @@
5050
"registry": "https://registry.npmjs.org/"
5151
},
5252
"devDependencies": {
53-
"@dr.pogodin/react-native-fs": "^2.22.0",
53+
"@dr.pogodin/react-native-fs": "^2.24.1",
5454
"@react-native/eslint-config": "^0.73.2",
5555
"@types/jest": "^29.5.11",
5656
"@types/react": "^18.2.48",
57-
"@types/uuid": "^9.0.7",
57+
"@types/uuid": "^9.0.8",
5858
"del-cli": "^5.1.0",
5959
"eslint": "^8.56.0",
6060
"eslint-config-prettier": "^9.1.0",
6161
"eslint-plugin-prettier": "^5.1.3",
6262
"jest": "^29.7.0",
63-
"metro-config": "^0.80.4",
63+
"metro-config": "^0.80.5",
6464
"pod-install": "^0.2.0",
6565
"prettier": "^3.2.4",
6666
"react": "18.2.0",

src/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ class StaticServer {
434434
if (!this._stateChangeEmitter.hasListeners) {
435435
throw Error(
436436
starting
437-
? 'Server auto-start on the app going into foreground failed'
438-
: 'Server auto-stop on the app going into background failed',
437+
? `Server (#${this._id}) auto-start on the app going into foreground failed`
438+
: `Server (#${this._id}) auto-stop on the app going into background failed`,
439439
);
440440
}
441441
}
@@ -463,6 +463,10 @@ export async function extractBundledAssets(
463463
into = DocumentDirectoryPath,
464464
from = '',
465465
) {
466+
console.warn(
467+
'extractBundledAssets() is deprecated! See: https://github.com/birdofpreyru/react-native-static-server?tab=readme-ov-file#extractbundledassets',
468+
);
469+
466470
if (Platform.OS !== 'android') return;
467471

468472
await mkdir(into);

0 commit comments

Comments
 (0)