@bayerjs/middleware
TypeScript icon, indicating that this package has built-in type declarations

0.2.0-alpha.0 • Public • Published

@bayerjs/middleware

Middleware functions to be used with the Bayer.js server library.

Static files

Handle static files simply by plugging the staticFiles middleware into your server.

import { staticFiles } from "@bayerjs/middleware";

// Will serve the "public" folder that's alongside this script file
app.use(staticFiles(join(__dirname, "public"), "/"))

app.listen();

By default, this middleware will check if the route points to a folder, and if it does, try to send the index.html file in that folder if found. To disable this, set useIndexFile to false. To change the extension of the index file, set indexExtension to the extension of your choice.

app.use(staticFiles(join(__dirname, "public"), "/", /*useIndexFile*/ true, /*indexExtension*/ "json"));

The middleware will check whether the file exists and is readable before streaming it to the client. The appropriate response codes will be used otherwise.

Readme

Keywords

Package Sidebar

Install

npm i @bayerjs/middleware

Weekly Downloads

2

Version

0.2.0-alpha.0

License

MIT

Unpacked Size

13.6 kB

Total Files

6

Last publish

Collaborators

  • solarliner