From 0c0e216e43f8afc3bac30e736ffc17aea66c4dcb Mon Sep 17 00:00:00 2001 From: "Dr. Sergey Pogodin" Date: Thu, 16 Nov 2023 20:40:01 +0100 Subject: [PATCH] [#88] Android: mod_rewrite support --- CMakeLists.txt | 1 + README.md | 29 +++++++++++++++++++++++++---- example/src/App.tsx | 9 +++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 788c46e4..3457df2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/README.md b/README.md index 8e226e19..f6d50293 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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 diff --git a/example/src/App.tsx b/example/src/App.tsx index 5250c3e4..910daa03 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -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; @@ -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: '' }} />