/uSendFile

A minimal static file handler for uWebSocket

Primary LanguageJavaScript

uSendFile

A minimal static file handler for uWebSocket.js

NOTE: Only works for small files. Apps in production should use nginx or similar.

Installation

Add the following to your package.json file:

{
  "dependencies": {
	"uSendFile": "github:erf/uSendFile"
  }
}

Then run npm install.

Usage

// import the modules 
import uWS from 'uWebSockets.js'
import sendFile from 'uSendFile'

// create a new app
const app = uWS.App()

// index.html
app.get('/', (res, req) => sendFile('./public/index.html', res))

// static files
app.get('/*', (res, req) => sendFile(`./public${req.getUrl()}`, res))

Test

node --test