A minimal static file cache handler for uWebSocket.js
NOTE: Only for small files.
Add the following to your package.json
file:
{
"dependencies": {
"uFileCache": "github:erf/uFileCache"
}
}
Then run npm install
.
// import the modules
import uWS from 'uWebSockets.js'
import FileCache from 'uFileCache'
const fileCache = new FileCache()
// load files in folder to memory
fileCache.init('public')
// create a new app
const app = uWS.App()
// index.html
app.get('/', (res, req) => fileCache.send('./public/index.html', res))
// static files
app.get('/*', (res, req) => fileCache.send(`./public${req.getUrl()}`, res))
node --test --no-warnings=ExperimentalWarning