Skip to content
Joshua Williams edited this page Jan 24, 2021 · 3 revisions

Home

The Silo Router needs no zero configuration to perform basic routing functions.

index.html
blog
    |_categories.jsx
    |_posts.jsx
    |_index.jsx
about
    |_contact
        |_index.html
        |_index.jsx
    |_our-mission
        |_index.html

Index File Mapping

The Router will attempt to map url requests without a file extension by appending it with the .jsx and .html file extension in that order.

If .jsx exists then it will be rendered as a React component. If .jsx does not exist but .html does exist then it will be streamed as a static file.

For example http://localhost/about/contact/ will map to /about/contact/index.html

If neither .html nor .jsx are mapped then silo attempts to map the request url to the respective directory on the file system appending the url with index.jsx and index.html in that order.

For example http://localhost/about/contact will map to '/blog/index.jsx' even though index.html also exists. Silojs takes a React first approach.

Request URL File
/ index.html
/blog blog/index.jsx
/blog/categories blog/categories.jsx
/about/contact about/contact/index.html

Getting Started

// Create silo instance
const app = silo();
// For all GET requests 
app.get('/', (req, res) => res.send("Hello World"))

Routing Lifecycle

  • If url maps to a file relative to application root directory
    • If cached
      • Get cached content
      • Set response body to cache content
      • Set header content-type by extension
      • Send http response
    • If extension is jsx
      • Render React component
      • Cache rendered output
      • Set rendered content to response body
      • Set content-type header to text/html
      • Send http response
    • Set header content-type by extension
    • Set response body to file content
    • Send http response
  • If url maps to a directory relative to application root directory
    • If index.jsx exists
      • Render React component
      • Cache rendered output
      • Set rendered content to response body
      • Set content-type header to text/html
      • Send http response
    • If index.html exists
      • Set header content-type to text/html
      • Set response body to file content
      • Send http response
  • If silo routes are configured do run explicit routing
Clone this wiki locally