Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for hosting a static content #208

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added assets/images/soul-RA-app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/soul-standalone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions docs/self-hosting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 and add an `api.js` file to it.:
```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
soul -d foobar.db --extensions /path/to/_extensions/
```
6. To verify that the app is working, open the following URL in your browser:
```
http://localhost:<port>/api/client
```
Loading