pr-render-static
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@priestine/routing Render Static Module

The pr-render-static module allows rendering static files using @priestine/routing.

Installation

yarn add @priestine/routing pr-render-static

Usage

It's as easy as registering a new GET route and assigning it RenderStatic.from(/* static file directory */) which returns an array of middleware that will search for a file in the directory provided as the argument (this is relative to your package.json), set required MIME type and fire the response containing the data. If the file does not exist, it will set status code to 404 and end the response with text/plain Content-Type header.

Example

import { HttpRouter } from '@priestine/routing';
import { RenderStatic } from 'pr-render-static';
 
const router = HttpRouter.empty()
  .get(/^\/static\/.*/, RenderStatic.from('static'))
;

NOTE

It is recommended to include RenderStatic as the very last item in your router in case static files are not rendered on a specific route (e.g. when you set up RenderStatic for /^.*$/) so that it is referred to as the last resort.

Dependencies (0)

    Dev Dependencies (11)

    Package Sidebar

    Install

    npm i pr-render-static

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    198 kB

    Total Files

    12

    Last publish

    Collaborators

    • priestine