1.1.0 • Published 6 years ago

@totemish/render-static v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

RenderStatic Task

Core Build Status codecov Commitizen friendly semantic-release downloads version license

Description

Totemish RenderStatic task is a module for @totemish/routing that allows to seamlessly integrate rendering static files from given folder.

Installation

npm i --save @totemish/routing @totemish/render-static

Usage

To start using RenderStatic task, simply put it inside your route definition and assign it to GET of required route. As Totemish Routing uses RegExp at its core, you can use * where necessary. For the sake of simplicity, RenderStatic provides a static method RenderStatic.from that creates an instance of RenderStatic. The argument passed to it is referred to as source folder for static files.

NOTE: It is recommended to register RenderStatic as the very last route in your route map.

NOTE: If RenderStatic cannot render a file for some reason, it doesn't set 404 status code on response object. You can do that manually, use another module or simply call @totemish/router's native NotFoundHandler.

When request comes into RenderStatic#process, it will either return the static file and break the pipeline or return unchanged context and pass it to the next action in the pipeline.

Example

import { HttpRouter } from '@totemish/routing';
import { RenderStatic } from '@totemish/render-static';

const router = HttpRouter.empty();

router
  // Your route definition

  .get('.+', RenderStatic.from('.'));