Mantra how-to guide

Run a static web page with Mantra

No need to host a web server to run a simple static web page. Just run Mantra with simple configuration

07-Apr-2022
A  A  A 

Sometimes, you need to publish a simple web page with static content and with minimal user interaction with no backend.

With Mantra, despite you can develop complex projects with high efficient backends, you can do this as well with a simple mantraconf.json file.

You can use this simple configuration for this scenario:

{
   "CurrentVersion": "1",
   "Apps": {
      "staticsite": { "Port": 8080 }
   },
   "Entities": {
      "default": {
         "provider": "sqlite",
         "databasepath": "./mystaticsite.db"
      }
   }
}

You can generate this simple configuration file with new-project Mantra command, and choosing Sqlite as data provider and any of the default web projects.

By default, if you don't set it specifically at config file, UI assets should be placed at /yourporjectfolder/frontend.

After this, just install this simple Mantra app:

$ mantrad install

And just run this static web site with:

$ mantrad startapp

And that's all, open you browser and open the static web site at http://localhost:8080.

To deploy this static web app with a public domain and in a server with any cloud or hosting provider, Mantra team recommends to use Nginx as reverse proxy (to route :80 requests to your app internal port, in this case, :8080), and PM2 for *daemonize" your Mantra app, as you can read at this how-to guides:

For last, cause your site is static, you can tell to Mantra to cache all content just enabling this in "static" component:

{
   "CurrentVersion": "1",
   "Apps": {
      "staticsite": { "Port": 8080 }
   },
   "ComponentsConfig": {
      "static": { "cached": true }
   },
   "Entities": {
      "default": {
         "provider": "sqlite",
         "databasepath": "./mystaticsite.db"
      }
   }
}