@@ -39,6 +39,7 @@ and [old][Old Architecture] RN architectures.
39
39
[ OLD-README.md ] : https://github.com/birdofpreyru/react-native-static-server/blob/master/OLD-README.md
40
40
[ getDeviceType() ] : https://www.npmjs.com/package/react-native-device-info#getDeviceType
41
41
[ MainBundlePath ] : https://www.npmjs.com/package/@dr.pogodin/react-native-fs#mainbundlepath
42
+ [ mod_alias ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_alias
42
43
[ mod_webdav ] : https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_webdav
43
44
[ react-native-device-info ] : https://www.npmjs.com/package/react-native-device-info
44
45
[ react-native-fs ] : https://www.npmjs.com/package/react-native-fs
@@ -50,6 +51,7 @@ and [old][Old Architecture] RN architectures.
50
51
51
52
- [ Getting Started] ( #getting-started )
52
53
- [ Bundling-in Server Assets Into an App Statically] ( #bundling-in-server-assets-into-an-app-statically )
54
+ - [ Enabling Alias module]
53
55
- [ Enabling WebDAV module]
54
56
- [ API Reference] ( #api-reference )
55
57
- [ Project History and Roadmap] ( #project-history-and-roadmap )
@@ -340,6 +342,40 @@ outside platform-specific sub-folders.
340
342
< /Target>
341
343
` ` `
342
344
345
+ # ## Enabling Alias Module
346
+ [Enabling Alias module]: # enabling-alias-module
347
+
348
+ [Lighttpd]'s optional module [mod_alias] is used to specify a special document
349
+ root for a given url-subset. To enable it:
350
+
351
+ 1. **Android**: Edit ` android/gradle.properties` file of your app, adding
352
+ this flag:
353
+ ` ` ` gradle
354
+ ReactNativeStaticServer_alias = true
355
+ ` ` `
356
+
357
+ ** iOS** : Use environment variable ` RN_STATIC_SERVER_ALIAS=1` when
358
+ installing or updating the pods (_i.e._ when doing ` pod install` or
359
+ ` pod update` ).
360
+
361
+ ** macOS (Catalyst)** : The same as for iOS.
362
+
363
+ ** Windows** : Does not require a special setup & mdash; the pre-compiled DLL
364
+ for [mod_alias] is always packed with the library, and loaded if opted
365
+ by [Server]' s [constructor()].
366
+
367
+ 2. Use `extraConfig` option of [Server] [constructor()] to load and configure
368
+ [mod_alias], for example:
369
+ ```ts
370
+ extraConfig: `
371
+ server.modules += ("mod_alias")
372
+ alias.url = ("/sample/url" => "/special/root/path")
373
+ `,
374
+ ```
375
+ With this configuration incoming request `GET /sample/url/file` will be
376
+ routed to the `/special/root/path/file`, rather than the `FILE_DIR/sample/url/file`,
377
+ where `FILE_DIR` is the value you provided to the [Server]' s ` fileDir` option.
378
+
343
379
# ## Enabling WebDAV Module
344
380
[Enabling WebDAV module]: # enabling-webdav-module
345
381
@@ -348,15 +384,11 @@ HTTP extensions that provides a framework allowing to create, change, and move
348
384
documents on a server — essentially an easy way to enable `POST`, `PUT`,
349
385
_etc._ functionality for selected routes.
350
386
351
- ** BEWARE:** _As of now, I only need it for implementing a local testing of
352
- network functionality inside [@dr.pogodin/react-native-fs] library, thus for
353
- development needs only, and I have not put efforts to build it with all features
354
- (support of props and locks), and have not looked much into what configuration
355
- is needed for its safe and flexible production use._
387
+ **BEWARE:** _As of now, props and locks are not supported._
356
388
357
389
To enable [mod_webdav] in the library you need (1) configure your host RN app
358
390
to build Lighttpd with [mod_webdav] included; (2) opt-in to use it for selected
359
- routes when you create [Server] instance inside your TypeScript code .
391
+ routes when you create [Server] instance, using `extraConfig` option .
360
392
361
393
1. **Android**: Edit `android/gradle.properties` file of your app, adding
362
394
this flag in there:
@@ -374,8 +406,16 @@ routes when you create [Server] instance inside your TypeScript code.
374
406
for [WebDAV] module is always packed with the library, and loaded if opted
375
407
for by [Server]' s [constructor()].
376
408
377
- 2. Use `webdav` option of [Server]' s [constructor()] to enable [WebDAV] for
378
- selected routes of the created server instance.
409
+ 2. Use ` extraConfig` option of [Server]' s [constructor()] to load [mod_webdav]
410
+ and use it for selected routes of the created server instance, for example:
411
+ ```ts
412
+ extraConfig: `
413
+ server.modules += ("mod_webdav")
414
+ $HTTP["url"] =~ "^/dav/($|/)" {
415
+ webdav.activate = "enable"
416
+ }
417
+ `,
418
+ ```
379
419
380
420
## API Reference
381
421
- [Server] — Represents a server instance.
@@ -452,6 +492,12 @@ within `options` argument:
452
492
**BEWARE:** If you opt for file logging with this option, it is up to you
453
493
to control and purge the [ERROR_LOG_FILE] as needed.
454
494
495
+ - `extraConfig` — **string** — Optional. If given, it should be
496
+ a valid piece of
497
+ [Lighttpd configuration](https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration),
498
+ and it will be appended to the base Lighttpd config generated by this
499
+ library according to the other server options.
500
+
455
501
- `hostname` — **string** — Optional. Sets the address for server
456
502
to bind to.
457
503
- By default, when `nonLocal` option is **false**, `hostname` is set equal
@@ -502,20 +548,9 @@ within `options` argument:
502
548
`details` values set equal "_App entered background_",
503
549
and "_App entered foreground_" strings.
504
550
505
- - ` webdav` & mdash; ** string[]** & mdash; Optional. Enables [WebDAV] for specified
506
- server routes. To use this option, first read [Enabling WebDAV module]. Each
507
- string inside provided ` webdav` array is expected to be a Perl-style regular
508
- expression for the route(s) on which [WebDAV] should be enabled. For example,
509
- to enable [WebDAV] for ` /dav` directory and everything below it, you should
510
- give ` webdav = [" ^/dav($|/)" ]` , which will add the following configuration
511
- to the internal [Lighttpd] config of the server:
512
- ` ` ` perl
513
- $HTTP [" url" ] =~ " ^/dav($|/)" {
514
- webdav.activate = " enable"
515
- }
516
- ` ` `
517
- As of now, we don' t yet support more advanced features and configurations for
518
- [mod_webdav].
551
+ - **DEPRECATED**: `webdav` — **string[]** — It still works, but it
552
+ will be removed in future versions. Instead of it use `extraConfig` option to
553
+ enable and configure [WebDAV] as necessary (see [Enabling WebDAV module]).
519
554
520
555
#### .addStateListener()
521
556
[.addStateListener()]: #addstatelistener
0 commit comments