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 a React Admin Application via Soul
In this guide, we will demonstrate how to host a static React Admin
application.
-
Create an
_extensions
folder and add anapi.js
file to it.:mkdir _extensions && touch _extensions/api.js
-
Add the following code to the
api.js
file: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); }, };
-
Build your React Admin client:
npm run build
-
Copy the
dist
folder from yourReact Admin
project to the_extensions
folder:cp -r dist <path/to/_extensions>
-
Run your Soul application:
soul -d foobar.db --extensions /path/to/_extensions/
-
To verify that the app is working, open the following URL in your browser:
http://localhost:<port>/api/client