Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

uwebsocket-serve

kolodziejczak-sz305ISC1.0.8TypeScript support: included

Static file serving for uWebSockets.js

socket, websocket, uwebsocket, uwebsocket.js, serve, file, dir, static, static-serve

readme

Static file serving for uWebSockets.js http server.

Example

import path from 'path';
import { App } from 'uWebSockets.js';
import { serveDir } from 'uwebsocket-serve';

const publicPath = path.resolve(__dirname, '../public');
const serveStatic = serveDir(publicPath);

App().get('/*', serveStatic);

API

const serveDir = (directoryPath: string) => (res: HttpResponse, req: HttpRequest) => void

serveDir(directoryPath: string)

Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining req.getUrl() with provided directory. When a file is not found sending a 404 response.

Cache

This module supports the Last-Modified HTTP header

Source

This library is based on an example from a uWebSockets.js repository.

Support

uwebsocket-serve is an MIT-licensed open source project. Feel free to fork and contribute.

changelog

[v1.0.8]

  • Fix warning related to uWS.HttpResponse.cork