Add docs for hosting a static content

This commit is contained in:
AbegaM
2024-06-17 14:17:41 +03:00
parent 86eac098d6
commit f30fdddd39
4 changed files with 59 additions and 0 deletions

View File

@@ -168,6 +168,10 @@ npm run dev # Start the dev server
Make sure to replace the placeholders with the appropriate values for your environment.
## Hosting Static Content Using Soul
You can host static content using Soul by utilizing its extensions feature. This allows you to expose your static application through Soul, enabling users to access your content without hosting multiple applications. please check [this](./docs//self-hosting.md) document
## Community
[Join](https://bit.ly/soul-discord) the discussion in our Discord server and help making Soul together.

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

55
docs/self-hosting.md Normal file
View File

@@ -0,0 +1,55 @@
# Hosting Static Content Using Soul
You can host static content using Soul by utilizing its extensions feature. This allows you to expose your static application through Soul, enabling users to access your content without hosting multiple applications.
Here are diagrams showing how to access Soul APIs when running standalone and how to expose a static client via extensions.
**Accessing Soul APIs**
![soul standalone](../assets/images/soul-standalone.png)
**Accessing a React Admin Application via Soul**
![soul RA app](../assets//images//soul-RA-app.png)
## Steps
In this guide, we will demonstrate how to host a static `React Admin` application.
1. Create an `_extensions` folder within the `Soul` directory and add a file named `api.js`:
```sh
mkdir _extensions && touch _extensions/api.js
```
2. Add the following code to the `api.js` file:
```js
const reactAdminApp = {
method: "GET",
path: "/api/client",
handler: (req, res, db) => {
const clientPath = path.join(__dirname, "../dist", "index.html");
res.app.use(express.static(path.join(__dirname, "../dist")));
res.sendFile(clientPath);
},
};
```
3. Build your React Admin client:
```sh
npm run build
```
4. Copy the `dist` folder from your `React Admin` project to the `_extensions` folder:
```sh
cp -r dist <path/to/_extensions>
```
5. Run your Soul application:
```sh
npm run dev
```
6. To verify that the app is working, open the following URL in your browser:
```
http://localhost:<port>/api/client
```