Clone

Configuration file

Syntax used in the configuration file.

Let’s start with an example and then let’s decompose the keys:

{
  "robots": true,
  "sitemap": true,
  "static_txt_content": [
    "hello.txt"
  ],
  "pages":[
    {
      "name": "post",
      "URLPattern": "/posts/:post",
      "BackendURLPattern": "https://jsonplaceholder.typicode.com/posts/:post",
      "Template": "post",
      "Layout": "main",
      "CacheTTL": "3600s"
    },
    {
      "name": "home",
      "URLPattern": "/",
      "BackendURLPattern": "https://jsonplaceholder.typicode.com/posts",
      "Template": "home",
      "Layout": "main",
      "CacheTTL": "3600s",
      "IsArray": true,
      "extra": {"is_home":true }
    }
  ],
  "templates": {"home":"home.mustache","post":"post.mustache"},
  "layouts": {"main":"main_layout.mustache"},
  "extra":{
    "lang": "en-US",
    "copyright": "© 2018 My Company"
  },
  "public_folder": {
    "path_to_folder": "./public",
    "url_prefix": "/"
  }
}

Root attributes

Page object

When declaring pages in the root the page object accepts the following attributes:

name: A friendly identifier for your page. Letters only, no spaces. URLPattern: The URL where API2HTML will listen. You can use variables using colons ( :var) BackendURLPattern: The API call that will be executed and injected inside the {{ Data }} variable. You can use the variables declared in URLPattern Template: The template name as defined in the templates attribute Layout: The layout that will encapsulate the template, as defined in the layouts attribute. CacheTTL (string): Time for the Cache-Control header added to the responses. Use s for seconds, h hours, m for minutes. E.g: 4h

Declare pages in the right order

The order of appearance of the pages is very important, as if you have conflicting routes the behavior might not be the one you expect. When handling routes that share a part of the pattern, always declare the most specific case first and go down to the most generalist. E.g:

/posts/:postid/detail
/posts/:postid
/posts
/

Continue to Templates

← Back to Creating your first site