Skip to content

Commit 0c0e216

Browse files
committed
[futurepress#88] Android: mod_rewrite support
1 parent 01b0907 commit 0c0e216

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ set(PLUGIN_STATIC
120120
PLUGIN_INIT(mod_dirlisting)\n
121121
PLUGIN_INIT(mod_h2)\n
122122
PLUGIN_INIT(mod_indexfile)\n
123+
PLUGIN_INIT(mod_rewrite)\n
123124
PLUGIN_INIT(mod_staticfile)\n
124125
)
125126

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ and [old][Old Architecture] RN architectures.
4040
[getDeviceType()]: https://www.npmjs.com/package/react-native-device-info#getDeviceType
4141
[MainBundlePath]: https://www.npmjs.com/package/@dr.pogodin/react-native-fs#mainbundlepath
4242
[mod_alias]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_alias
43+
[mod_rewrite]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_rewrite
4344
[mod_webdav]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_webdav
4445
[react-native-device-info]: https://www.npmjs.com/package/react-native-device-info
4546
[react-native-fs]: https://www.npmjs.com/package/react-native-fs
@@ -52,6 +53,7 @@ and [old][Old Architecture] RN architectures.
5253
- [Getting Started](#getting-started)
5354
- [Bundling-in Server Assets Into an App Statically](#bundling-in-server-assets-into-an-app-statically)
5455
- [Enabling Alias module]
56+
- [Enabling Rewrite module]
5557
- [Enabling WebDAV module]
5658
- [API Reference](#api-reference)
5759
- [Project History and Roadmap](#project-history-and-roadmap)
@@ -360,10 +362,29 @@ root for a given url-subset. To enable it just use `extraConfig` option of
360362
[Server] [constructor()] to load and configure it, for example:
361363
362364
```ts
363-
extraConfig: `
364-
server.modules += ("mod_alias")
365-
alias.url = ("/sample/url" => "/special/root/path")
366-
`,
365+
extraConfig: `
366+
server.modules += ("mod_alias")
367+
alias.url = ("/sample/url" => "/special/root/path")
368+
`,
369+
```
370+
371+
### Enabling Rewrite Module
372+
[Enabling Rewrite module]: #enabling-rewrite-module
373+
374+
[Lighttpd]'s module [mod_rewrite] can be used for interal redirects,
375+
URL rewrites by the server. To enable it just use `extraConfig` option of
376+
[Server] [constructor()] to load and configure it, for example:
377+
378+
```ts
379+
extraConfig: `
380+
server.modules += ("mod_rewrite")
381+
url.rewrite-once = ("/some/path/(.*)" => "/$1")
382+
`,
383+
384+
// With such configuration, for example, a request
385+
// GET "/some/path/file"
386+
// will be redirected to
387+
// GET "/file"
367388
```
368389
369390
### Enabling WebDAV Module

example/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export default function App() {
7878
// webdav: ['^/dav($|/)'],
7979

8080
extraConfig: `
81-
server.modules += ("mod_alias")
81+
server.modules += ("mod_alias", "mod_rewrite")
8282
alias.url = (
8383
"/some/path" => "${fileDir}"
8484
)
85+
url.rewrite-once = ( "/bad/path/(.*)" => "/$1" )
8586
`,
8687
});
8788
const serverId = server.id;
@@ -202,7 +203,11 @@ export default function App() {
202203
// window - as we rather want to show a blank page until the server
203204
// is up and running, we should thus prefer to define an empty `html`
204205
// field in such case.
205-
source={origin ? { uri: origin } : { html: '' }}
206+
// NOTE: Now it is setting `source` to a `/bad/path` endpoint of
207+
// the origin, to test the path rewrite with mod_rewrite...
208+
// TODO: Need to rework the example app later, to have tests of different
209+
// modules on different screens.
210+
source={origin ? { uri: `${origin}/bad/path/` } : { html: '' }}
206211
/>
207212
</View>
208213
<View style={styles.webview}>

0 commit comments

Comments
 (0)