FaasJS
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文

Documents / @faasjs/server / staticHandler

Function: staticHandler()

staticHandler(options): Middleware

Middleware to handle static file requests.

Parameters

options

StaticHandlerOptions

Options for the static handler.

Returns

Middleware

The middleware function.

The middleware resolves the requested URL to a file path within the specified root directory. If the file exists, it reads the file content and sends it in the response. If the file does not exist, it does nothing.

Example

import { useMiddleware, staticHandler } from '@faasjs/server'

export const func = useMiddleware(staticHandler({ root: __dirname + '/public' }))