Skip to content

Commit

Permalink
[futurepress#88] Android: mod_rewrite support
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Nov 16, 2023
1 parent 01b0907 commit 0c0e216
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ set(PLUGIN_STATIC
PLUGIN_INIT(mod_dirlisting)\n
PLUGIN_INIT(mod_h2)\n
PLUGIN_INIT(mod_indexfile)\n
PLUGIN_INIT(mod_rewrite)\n
PLUGIN_INIT(mod_staticfile)\n
)

Expand Down
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and [old][Old Architecture] RN architectures.
[getDeviceType()]: https://www.npmjs.com/package/react-native-device-info#getDeviceType
[MainBundlePath]: https://www.npmjs.com/package/@dr.pogodin/react-native-fs#mainbundlepath
[mod_alias]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_alias
[mod_rewrite]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_rewrite
[mod_webdav]: https://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_webdav
[react-native-device-info]: https://www.npmjs.com/package/react-native-device-info
[react-native-fs]: https://www.npmjs.com/package/react-native-fs
Expand All @@ -52,6 +53,7 @@ and [old][Old Architecture] RN architectures.
- [Getting Started](#getting-started)
- [Bundling-in Server Assets Into an App Statically](#bundling-in-server-assets-into-an-app-statically)
- [Enabling Alias module]
- [Enabling Rewrite module]
- [Enabling WebDAV module]
- [API Reference](#api-reference)
- [Project History and Roadmap](#project-history-and-roadmap)
Expand Down Expand Up @@ -360,10 +362,29 @@ root for a given url-subset. To enable it just use `extraConfig` option of
[Server] [constructor()] to load and configure it, for example:
```ts
extraConfig: `
server.modules += ("mod_alias")
alias.url = ("/sample/url" => "/special/root/path")
`,
extraConfig: `
server.modules += ("mod_alias")
alias.url = ("/sample/url" => "/special/root/path")
`,
```
### Enabling Rewrite Module
[Enabling Rewrite module]: #enabling-rewrite-module
[Lighttpd]'s module [mod_rewrite] can be used for interal redirects,
URL rewrites by the server. To enable it just use `extraConfig` option of
[Server] [constructor()] to load and configure it, for example:
```ts
extraConfig: `
server.modules += ("mod_rewrite")
url.rewrite-once = ("/some/path/(.*)" => "/$1")
`,
// With such configuration, for example, a request
// GET "/some/path/file"
// will be redirected to
// GET "/file"
```
### Enabling WebDAV Module
Expand Down
9 changes: 7 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ export default function App() {
// webdav: ['^/dav($|/)'],

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

0 comments on commit 0c0e216

Please sign in to comment.